如何在sql server中获取从当前日期时间到最近7天的最后7天数据

您好,我正在使用 pentaho 将表 A 数据从 sql server 加载到 mysql加载数据时,我只需要从 sql server A table 获取最近 7 天的数据到 mysql在 sql server createddate 列数据类型类似于 datetime AND在 mysql created_on 列数据类型是时间戳

Hi I am loading table A data from sql server to mysql using pentaho when loading data i need to get only last 7 days data from sql server A table to mysql In sql server createddate column data type is like datetime AND In mysql created_on column datatype is timestamp

这里我使用了下面的查询,但我只得到了 5 天的数据
请帮我解决这个问题

Here I used below query but i am getting only 5 days data
Please help me in this issue

select id,    
NewsHeadline as news_headline,    
NewsText as news_text,    
state,    
CreatedDate as created_on      
from News    
WHERE CreatedDate BETWEEN GETDATE()-7 AND GETDATE()
order by createddate DESC

推荐答案

试试这样的:

 SELECT id, NewsHeadline as news_headline, NewsText as news_text, state CreatedDate as created_on
 FROM News 
 WHERE CreatedDate >= DATEADD(day,-7, GETDATE())

相关文章