1

I have used a query which is like

SELECT app_id, SUM(amount), date 
FROM abc 
GROUP BY app_id,date

Result is show as follows

1   10   1-2-2000
2   20   1-2-2000
3   30   1-2-2000
1   20   2-2-2000
2   40   2-2-2000
3   50   2-2-2000

I want to get desired result with new column

1   10   1-2-2000
2   30   1-2-2000   # sum of amount of app_id=1 and app_id=2
3   60   1-2-2000   # sum of amount of app_id=1 and app_id=2 and app_id=3
1   20   2-2-2000
2   60   2-2-2000   # sum of amount of app_id=1 and app_id=2
3  110   2-2-2000   # sum of amount of app_id=1 and app_id=2 and app_id=3
Saharsh Shah
  • 28,687
  • 8
  • 48
  • 83
Sunny Sunny
  • 3,204
  • 4
  • 25
  • 26
  • So you want to display the Product_ID (2) but at the same time display the amount of Product_ID 2 and 3? Very strange and illogical requirements – Ahmad Nov 05 '12 at 12:39

1 Answers1

0

Try this:

SELECT a.app_id, (SELECT SUM(amount) FROM abc b WHERE a.date = b.date AND b.app_id <= a.app_id) amount, a.date 
FROM abc a;
Saharsh Shah
  • 28,687
  • 8
  • 48
  • 83