I don't know how to return the last date of the month. Currently I have only this SQL statement which returns the last 12 months:
SELECT *
FROM KENNZAHL
WHERE ID=325 And Datum>=DateAdd("m",-12,Date())
ORDER BY Datum DESC;
It is good, but I need only the last date of these 12 months. Do anyone has an idea?
ps: I'm using ms access 2010.
for example:
Result:
ID | Datum
325 | 2017-01-31
325 | 2016-12-31
325 | 2016-11-30
325 | 2016-10-31
325 | 2016-09-31
.....
The maximum date per month:
SELECT MAX(Datum)
FROM KENNZAHL
WHERE ID=325 And Datum>=DateAdd("m",-12,Date())
GROUP BY YEAR(Datum), MONTH(Datum)
ORDER BY YEAR(Datum) DESC, MONTH(Datum) DESC;
If there´s only one entry with that last date you could use
SELECT TOP 1 *
FROM KENNZAHL
WHERE ID=325
ORDER BY Datum DESC;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.