I'm working on a site where I showing results on a chart grouped by date but I like to show only the last three results.
In ASC
order the the first point of the chart starts on the left side but if I have more than three results the first three appears and thats ot what I want.
If I order my result in DESC
by the date
it changing the order and it is OK but the last three results (that I need) takes the firs places on the left side (like on the image).
I like to show the last three results from left to right. How could I do that?
This is what I have now:
SELECT * FROM table
GROUP BY strftime("%%Y-%%m", date)
ORDER BY max(strftime("%%Y-%%m", date)) DESC
LIMIT 3
CodePudding user response:
Can you wrap in another query?
like:
select *
from(
SELECT thedate, thedata FROM table
GROUP BY strftime("%%Y-%%m", date)
ORDER BY max(strftime("%%Y-%%m", date)) DESC
LIMIT 3
) details
order by details.thedate