In mysql I need to obtain all the last 5 days records. So if I have
Name date
aaaa 20/11/2010
dddd* 24/11/2010*
bbbb 22/11/2010
cccc 23/11/2010
eeee* 25/11/2010*
ffff* 26/11/2010*
I need only the last 5 days records.
I tried something like:
SELECT name,date
from Lineas
WHERE date >= DATE_SUB(CURDATE(), INTERVAL 5 DAY)
ORDER BY date DESC
but it isn´t working....
If the problem is "records from the future" then you simply need to restrain your results a bit more than you've already done:
SELECT name,date
from Lineas
WHERE date >= DATE_SUB(CURDATE(), INTERVAL 5 DAY) AND date <= CURDATE()
ORDER BY date DESC
Have you tried between
SELECT name,
date
from Lineas
WHERE date BETWEEN DATE_SUB(CURDATE(), INTERVAL 5 DAY) AND CURDATE()
ORDER BY date 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.