--查询近7天数据记录⾏数,没有返回0
select a.click_date,ISNULL(b.count,0) as countfrom (
SELECT convert(varchar(10),getdate()-7,120) as click_dateunion all
SELECT convert(varchar(10),getdate()-6,120) as click_dateunion all
SELECT convert(varchar(10),getdate()-5,120) as click_dateunion all
SELECT convert(varchar(10),getdate()-4,120) as click_dateunion all
SELECT convert(varchar(10),getdate()-3,120) as click_dateunion all
SELECT convert(varchar(10),getdate()-2,120) as click_dateunion all
SELECT convert(varchar(10),getdate()-1,120) as click_date) a left join (
select convert(varchar(10),TimeOver,120) as datetime, count(*) as countfrom tableName(表名) where ChargeUId(字段)=45 group by convert(varchar(10),TimeOver,120)) b on a.click_date = b.datetime;
--查询近七天的数据内容
select * from Project_Task where DateDiff(dd,AddTime,getdate())<=7
--查询N天的数据内容
select * from Project_Task where DateDiff(dd,AddTime,getdate())<=N
因篇幅问题不能全部显示,请点此查看更多更全内容