0
我有如下表:总和(或计数)多个case语句
Month | Item | Events | Party | Spirit | Faith |
May | 123 | 1 | 1 | 0 | 0 |
June |123 | 1 | 0 | 1 | 1 |
它基本上是1是0否。我需要知道每个项目多少不同的类别是每个月
我需要的结果如下:
Month | Item | Counts |
May | 123 | 2 |
June| 123 | 3 |
这是行不通的:
select Month, Item,
sum(case when EVENTS = 1 then 1 when PARTY = 1 then 1 when SPIRIT = 1 then 1 when FAITH = 1 then 1 else 0 end) as Counts
from TABLE
group by 1,2
请帮帮忙,谢谢!
请格式化您的代码,以便它更具可读性,还有一些解释为什么它的作品会很好 –