I have this MS-SQL query with thousands of row records in database:
SELECT DISTINCT TOP 7 DATENAME(MM, mydatetime) + \' \' + CAST(DAY(mydatetime) AS VA
For your actual requirement, you can use your current query as a derived table and order that result in the way you want:
SELECT *
FROM ( SELECT DISTINCT TOP 7 DATENAME(mm, mydatetime) + ' '
+ CAST(DAY(mydatetime) AS VARCHAR(2)) AS thedate,
MONTH(mydatetime) AS theMonth,
DAY(mydatetime) AS theDay,
COUNT(page) AS totalcount,
COUNT(DISTINCT page) AS visitors
FROM sometable
WHERE page LIKE '%AEC%'
GROUP BY DATENAME(mm, mydatetime) + ' '
+ CAST(DAY(mydatetime) AS VARCHAR(2)),
MONTH(mydatetime),
DAY(mydatetime)
ORDER BY MONTH(mydatetime) DESC,
DAY(mydatetime) DESC) A
ORDER BY theMonth, theDay