Select all data from the last 5 days
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
精彩评论