[thelist] Monthly Counts in order
Michele Foster (WizarDev)
michele at wizardev.ca
Tue May 10 02:21:21 CDT 2005
Another SQL question ...
SELECT Month(RefDate) as MyMonth, Year(RefDate) as MyYear, COUNT
(Month(RefDate)) AS MonthlyTotal
FROM ext_Refs
GROUP BY Month(RefDate), Year(RefDate)
This is giving me the correct totals for the month ..
October 2004 = 32
January 2005 = 158
May 2004 = 44
However, I need the output in chronological order (May 2005 first). Can't
seem to get an ORDER BY to work .. and still give me the monthly totals.
If I add the ORDER BY to the end, after the GROUP BY, I get this error:
Column name 'ext_Refs.RefDate' is invalid in the ORDER BY clause because it
is not contained in either an aggregate function or the GROUP BY clause.
If I add RefDate to the GROUP BY clause, gets rid of the above error, but I
no longer get monthly totals, but daily totals instead.
I'm stumped ... perhaps because it's after 3:00 a.m. ;)
Thanks,
Mich
More information about the thelist
mailing list