query on cumulative sum.....

Database

query on cumulative sum.....

Hi Dieter,

My sql requirement is as below.  Please find below sample data.

can you please help in writing SQL...









Date Name Meaure Cumm. Measure by Name Measure Total Cumm. Measure By Date
1-Jul A 10 10 17 17
1-Jul B 5 5
1-Jul C 2 2
1-Jul D 0 0
2-Jul A 4 14 7 24
2-Jul B 0 5
2-Jul C 3 5
2-Jul D 0 0
3-Jul A 15 29 23 47
3-Jul B 0 5
3-Jul C 0 5
3-Jul D 8 8

Regards,

Ramaiah

2 REPLIES

Re: query on cumulative sum.....

the table data is like below.

Date                             Name                      Measure

2013-07-01                    A                            10

2013-07-01                    B                            5

2013-07-01                    C                            2

2013-07-02                    A                            4

2013-07-02                    C                            2

2013-07-01                    A                             15

2013-07-01                    D                              8

My out should be like below:

name              mesure              date             CUM_AMT

A                     10                   7/1/2013         10

A                       4                   7/2/2013          14

A                     15                   7/3/2013         29

B                        5                   7/1/2013         5

B                        0                    7/2/2013         5

B                        0                    7/3/2013         5

C                        2                      7/1/2013       2

C                        3                      7/2/2013       3

C                        0                       7/3/2013      5

D                        0                       7/1/2013        0

D                        0                          7/2/2013      0

D                        8                         7/3/2013      8

like this so on... i have to get the cumulative sum for the dates which are not present in source table also...My source table is having 139 M records..

Regards,

Ramaiah

Enthusiast

Re: query on cumulative sum.....