提问者:小点点

如何为单列中的值添加多个条件,并在单独的列中显示结果?


我的表的结构如下所示。

我需要编写一个查询,该查询将给出如下所示的结果:


共1个答案

匿名用户

以下是你如何做到这一点:

select number 
       , count(*) total
       , count(case when status = 'fail' then 1 end) fail_count
       , count(case when status = 'success' then 1 end) success_count
from yourtable
group by number