General information
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Sum for last 12 months only
Hi all,
I have mytable that data like this :
mytable.dbf
date amount categ
2006-09-10 100000 A
2006-08-10 200000 B
2006-07-10 300000 C
2006-06-10 400000 E
2006-05-10 500000 F
2006-04-10 100000 A
2006-03-10 200000 B
2006-02-10 300000 C
2006-01-10 400000 E
2005-12-10 500000 F
2005-11-10 100000 A
2005-10-10 200000 B
2005-09-10 300000 C
2005-08-10 400000 E
2006-05-10 500000 F
2006-09-10 100000 A
2006-08-10 200000 B
2006-07-10 300000 C
2006-06-10 400000 E
2006-05-10 500000 F
to have newtable.dbf for last 12 months only,
date amountsum categ datecount
2006-09-10 200000 A 2
2006-08-10 400000 B 2
2006-07-10 600000 C 2
2006-06-10 800000 E 2
2006-05-10 1000000 F 2
2006-04-10 100000 A 1
2006-03-10 200000 B 1
2006-02-10 300000 C 1
2006-01-10 400000 E 1
2005-12-10 500000 F 1
2005-11-10 100000 A 1
2005-10-10 200000 B 1
I try this :
select date,sum(amount) as amountsum,categ, count(date) as datecount
from mytable group by date,amount
Am i missing something ? please assist to fix my sql.
TIA
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only