select count(distinct ip,datediff(char(10), visitetime,120)),count(1) from tb union all 
select count(distinct ip,datediff(char(10), visitetime,120)),count(1) from tb where datediff(char(10), visitetime,120)) = datediff(char(10),getdate(),120) union all
select count(distinct ip,datediff(char(10), visitetime,120)),count(1) from tb where datediff(char(10), visitetime,120)) = datediff(char(10),dateadd(day,-1,getdate()),120) union all
select count(distinct ip,datediff(char(10), visitetime,120)),count(1) from tb where datediff(char(7), visitetime,120)) = datediff(char(7),getdate(),120) union all
select count(distinct ip,datediff(char(5), visitetime,120)),count(1) from tb where datediff(char(5), visitetime,120)) = datediff(char(5),getdate(),120) union all

解决方案 »

  1.   

    调试时出现提示说“,附近有语法错误”,我根据实际情况写成这样的语句
    select count(distinct ip,datediff(char(10),visitetime,120)) as totalip,count(1) as totalnum from dbo.t_newitemwebvisiterecord union all 
    select count(distinct ip,datediff(char(10), visitetime,120)) as todayip,count(1) as todaynum from dbo.t_newitemwebvisiterecord where datediff(char(10), visitetime,120)) = datediff(char(10),getdate(),120) union all
    select count(distinct ip,datediff(char(10), visitetime,120)) as yesip,count(1) as yesnum from dbo.t_newitemwebvisiterecord where datediff(char(10), visitetime,120)) = datediff(char(10),dateadd(day,-1,getdate()),120) union all
    select count(distinct ip,datediff(char(10), visitetime,120)) as monip,count(1) as monnum from dbo.t_newitemwebvisiterecord where datediff(char(7), visitetime,120)) = datediff(char(7),getdate(),120) union all
    select count(distinct ip,datediff(char(5), visitetime,120)) as yearip,count(1) as yearnum from dbo.t_newitemwebvisiterecord where datediff(char(5), visitetime,120)) = datediff(char(5),getdate(),120) union all
    不知道对不对?