List:General Discussion« Previous MessageNext Message »
From:Gabriel PREDA Date:July 10 2006 8:28am
Subject:Re: Cumulative Totals
View as plain text  
> "cumulative total index"
> ...
> > > >SELECT SUM(amount) , DATE_FORMAT( `paymentDate` , '%Y-%m' )   FROM
> > > >`payments`   GROUP BY DATE_FORMAT( payments . date , '%Y-%m' )
>>>>> .....
> > > >Is there any way to get a running cumulative total directly from
> mysql?
> > > >Something like:
> > > >
> > > >amount | paymentDate
> > > >200    | 2005-01
> > > >258    | 2005-02

Will "WITH ROLLUP" do what you want ?

SELECT SUM(amount) , DATE_FORMAT( `paymentDate` , '%Y-%m' )   FROM
`payments` GROUP BY DATE_FORMAT( payments . date , '%Y-%m' ) WITH
ROLLUP

This will give you something like:
amount | paymentDate
200 | 2005-01
58   | 2005-02
258 | NULL

Will it do ?

-- 
Gabriel PREDA
Senior Web Developer
Thread
Efficiently finding a random recordBrian Dunning13 May
  • Re: Efficiently finding a random recordFrank Bax13 May
    • Cumulative TotalsRussell Horn25 May
      • Re: Cumulative TotalsDan Bolser25 May
        • Re: Cumulative Totalsdoug27 May
          • Re: Cumulative TotalsFrederik Eaton10 Jul
            • Re: Cumulative TotalsGabriel PREDA10 Jul
      • Re: Cumulative TotalsBrent Baisley25 May
    • Re: Cumulative TotalsRhino25 May
      • Re: Cumulative Totalsmfatene25 May
        • Re: Cumulative Totalsmfatene25 May
  • Re: Efficiently finding a random recordPhilip Hallstrom13 May
    • Re: Efficiently finding a random recordEric Bergen13 May
      • Re: Efficiently finding a random recordDan Bolser14 May
        • Re: Efficiently finding a random recordEric Bergen14 May
          • Re: Efficiently finding a random recordMichael Stassen15 May
        • Re: Efficiently finding a random recordGary Huntress15 May
          • Re: Efficiently finding a random recordmfatene15 May
        • Re: Efficiently finding a random recordGary Huntress15 May
          • Re: Efficiently finding a random recordMichael Stassen15 May
            • Re: Efficiently finding a random recordKeith Ivey16 May
              • Re: Efficiently finding a random recordPhilip Hallstrom16 May