SqlServer 根据时间统计数据展示图表
发布时间:2020-12-12 14:22:24 所属栏目:MsSql教程 来源:网络整理
导读:? -- 本年 select m as [ Date ] , sum ( case when datepart ( month ,CreateDateTime) = m then 1 else 0 end ) as [ Count ] from [ dbo ] .CrmCustomer c,( select 1 m union all select 2 union all select 3 union all select 4 union all select 5 un
? --本年 select m as [Date],sum(case when datepart(month,CreateDateTime)=m then 1 else 0 end )as [Count] from [dbo].CrmCustomer c,(select 1 m union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9 union all select 10 union all select 11 union all select 12) aa where ‘2018‘= year(CreateDateTime) group by m; --本月 select DATEPART(day,CreateDateTime) as [Date],COUNT(id) AS [Count] from [dbo].CrmCustomer WHERE DATEPART(mm,CreateDateTime) = DATEPART(mm,GETDATE()) and DATEPART(yy,CreateDateTime) = DATEPART(yy,GETDATE()) group by DATEPART(day,CreateDateTime) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |