I'm little confused while writing one SQL, actually the condition is little complicated. I'll try to express the condition please help me to sort this out.
In the table there are 4 fields, one is ID one is amount one is month and last one is year.
ID amount month year
1 10000 january 2013
2 5000 january 2013
3 7000 february 2013
4 9000 february 2013
5 6000 february 2013
6 5000 march 2013
7 6000 march 2013
8 1000 march 2013
9 8000 april 2013
10 7000 april 2013
Now while i need to generate january 2013 amount
SELECT SUM(amount) FROM table where month='january' and year='2013'
But now i want, if i choose february i'll get january+february sum amount
Same way, while choosing march, query returns january+february+march sum amount
while april, it'll return january+february+marcha+april sum amount
That means i just select the month and query will return sum amount till that month, so how do i solve this problem?
Thanks in advance.