开发者

Select all data from the last 5 days

开发者 https://www.devze.com 2023-02-01 03:15 出处:网络
In mysql I need to obtain all the last 5 days records. So if I have Namedate aaaa20/11/2010 dddd*24/11/2010*

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 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号