SQL SERVER常用的统计用法
--查询各个状态下总数
SET statistics time on Go SELECT sum(CASE WHEN [Status] =-1 THEN 1 ELSE 0 END ) AS Q1, sum(CASE WHEN [Status] =0 THEN 1 ELSE 0 END ) AS Q2, sum(CASE WHEN [Status] =1 THEN 1 ELSE 0 END ) AS Q3, sum(CASE WHEN [Status] =2 THEN 1 ELSE 0 END ) AS Q4, sum(CASE WHEN [Status] =3 THEN 1 ELSE 0 END ) AS Q5, sum(CASE WHEN [Status] =4 THEN 1 ELSE 0 END ) AS Q6, sum(CASE WHEN [Status] =5 THEN 1 ELSE 0 END ) AS Q7 FROM OrderInfo GO set statistics time off