SQL SERVER常用的统计用法
时间:2021-07-01 10:21:17
帮助过:33人阅读
统计各种状态的总个数
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
SQL SERVER常用的统计用法
标签:status 用法 状态 from -- logs stat cas else