我试图找出如何根据case
声明计算出现次数:
select
case
when name.ssn > 0
then 'YES'
when name.taxid > 0
then 'NO'
else 'OTHER' end "Category",
name.created
from
name
where
name.id = 11111
我现在想在一列中返回YES
s,OTHER
和NO
的计数,但似乎无法弄清楚如何做到这一点。
答案 0 :(得分:1)
您只需要按语句
计算结果select count(col),col from(
select
case
when name.ssn > 0
then 'YES'
when name.taxid > 0
then 'NO'
else 'OTHER' end as col,
name.created
from
name
where
name.id = 11111
) group by col;