R
Rick Brandt
Dave said:I need to GROUP BY a date and also SORT BY the date.
But the sort order in Access treats the date as a string rather than
a date.
For example, I have this query:
SELECT Format([createdate],'short date') AS [Date],
Count(stats.statsid) AS CountOfstatsid
FROM stats
WHERE stats.URL = 'z.asp'
GROUP BY Format([createdate],'short date')
ORDER BY Format([createdate],'short date') desc;
Which reurns records in the following order:
12/1/2005 55
11/6/2005 1
11/29/2005 28
11/27/2005 33
11/26/2005 77
11/19/2005 1
How can I write query that groups by day and sorts by date?
Include an additional version of the date that will sort in chronological order.
SELECT Format([createdate],'short date') AS [Date],
Format([createdate, 'yyyymmdd') AS SortVal,
Count(stats.statsid) AS CountOfstatsid
FROM stats
WHERE stats.URL = 'z.asp'
GROUP BY Format([createdate],'short date'), Format([createdate, 'yyyymmdd')
ORDER BY Format([createdate, 'yyyymmdd') desc;