计算同一行中具有多个条件的案例
count case with multiple conditions in same row
我需要从 s.status
列导出状态数据,例如
select s.name,
count(CASE WHEN s.STATUS = 'Active' THEN 1 END) AS Active_count,
count(CASE WHEN s.STATUS = 'Expired' THEN 1 END) AS Expired_count,
count(CASE WHEN s.STATUS = 'In Progress' THEN 1 END) AS InProgress_count
from my.table s
group by s.name,s.status
我希望它被算在一行中,但我却得到了这样的东西
https://i.stack.imgur.com/K4wyc.png
谁能帮我写一下,这样我就可以得到一行中的数据了?
谢谢
通过
从您的群组中删除s.status
我需要从 s.status
列导出状态数据,例如
select s.name,
count(CASE WHEN s.STATUS = 'Active' THEN 1 END) AS Active_count,
count(CASE WHEN s.STATUS = 'Expired' THEN 1 END) AS Expired_count,
count(CASE WHEN s.STATUS = 'In Progress' THEN 1 END) AS InProgress_count
from my.table s
group by s.name,s.status
我希望它被算在一行中,但我却得到了这样的东西
https://i.stack.imgur.com/K4wyc.png
谁能帮我写一下,这样我就可以得到一行中的数据了?
谢谢
通过
从您的群组中删除s.status