I have a table with 4 columns Id, Date, Material, Amount
.
Sample data looks like this :
--------------------------------------------
Id | Date | Material| Amount
--------------------------------------------
1 | 01/01/2013 | 1 | 500
2 | 01/01/2013 | 2 | 400
3 | 01/01/2013 | 1 | 200
4 | 02/01/2013 | 1 | 600
5 | 02/01/2013 | 2 | 200
6 | 03/01/2013 | 2 | 100
7 | 04/01/2013 | 1 | 800
8 | 05/01/2013 | 2 | 400
9 | 06/01/2013 | 1 | 800
10 | 06/01/2013 | 2 | 700
11 | 06/01/2013 | 1 | 600
I need to write a query to get the result like this :
-----------------------------------------------
Date | Material | DailyAmount | Total
-----------------------------------------------
01/01/2013 | 1 | 700 | 700
02/01/2013 | 1 | 400 | 1100
04/01/2013 | 1 | 800 | 1900
06/01/2013 | 1 | 1400 | 3300
Dailyamount
is sum of Amount
in a date. I just want to select Material = 1
. the Total
field is sum of DailyAmount
until that day.
I searched much, but I can't get anything about this ...