clamum
Lifer
I have a SQL query for an Android app I've been working on that I can't seem to get the ordering right for. Here it is:
The "shot_track" table has a "date" column that I store dates in, with "YYYY-MM-DD" format (per sqlite specs). What I want to do is order the results by "year", with newest first, and then by "month" (also newest first).
I don't quite understand why this query isn't doing that. The screenshot below is the results of the query with the data I have in the table now:
Any idea why the ordering isn't correct? If I take the "month" off the "ORDER BY" clause, the ordering is correct, but I want the months also ordered descending, after years.
Code:
SELECT DISTINCT strftime('%Y', [date]) AS [year],
strftime('%m', [date]) AS [month],
firearmId AS [_id],
COUNT([st].[firearmId]) AS [numDates]
FROM [shot_track] AS [st]
WHERE [st].[deleted] = '0'
AND [st].[firearmId] = '1'
GROUP BY [year], [month]
ORDER BY [year], [month] DESC
I don't quite understand why this query isn't doing that. The screenshot below is the results of the query with the data I have in the table now:
Any idea why the ordering isn't correct? If I take the "month" off the "ORDER BY" clause, the ordering is correct, but I want the months also ordered descending, after years.