我有这样的选择:
SELECT
[Status] AS Requested
,[Status] AS [Sent]
,[Status] AS Finished
FROM Store.[Order]
Status
是一个int值,我想要Count all Status
我怎样才能实现它?此致
答案 0 :(得分:2)
使用case
表达式根据值( 1,2,3 )计算状态
SELECT
SUM(CASE WHEN [Status] = 1 THEN 1 ELSE 0 END) AS Requested,
SUM(CASE WHEN [Status] = 2 THEN 1 ELSE 0 END) AS Sent,
SUM(CASE WHEN [Status] = 3 THEN 1 ELSE 0 END) AS Finished
FROM Store.[Order]