Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sum for last 12 months only
Message
From
21/09/2006 09:58:41
 
 
To
21/09/2006 09:37:35
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01155954
Message ID:
01155963
Views:
20
>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

Paul,

Not tested but this might be a little better.
dStart = GOMONTH(DATE() - 12)
SELECT Date, SUM(Amount) as AmountSum, Categ, COUNT(Date) as DateCoount ;
  FROM MyTable ;
 WHERE Date >= dStart ;
 GROUP BY Date, Categ
Regards,
Jim
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform