If you want to sort by month and day, you need a month, of course.
And you always need ORDER BY to guarantee the order of the result.
SELECT COUNT(UserId) AS c, MONTH(CreateDate) AS m, DAY(CreateDate) AS d
FROM dbo.aspnet_Membership
WHERE (CreateDate BETWEEN '2012/1/21' AND '2012/2/19')
GROUP BY MONTH(CreateDate) AS m, DAY(CreateDate) AS d
ORDER BY MONTH(CreateDate) AS m, DAY(CreateDate) AS d
In this case, the order you received was a coincidence due to GROUP BY (which implies ORDER BY in MySQL, but not in other DBMSs)
source
share