怎样用一句sql,统计表中不同状态的行的个数?

数据库中的数据是这样的:

筛选出来的数据是这样的:

怎样用一句sql,把数据从数据库中筛选出来,实现上图的结果?

解决:

select 系统名称,
sum(case when 故障状态='已处理' then else endas 已处理个数,
sum(case when 故障状态='未处理' then else endas 未处理个数,
count(*) as 总个数
from 表名

group by 系统名称

链接:http://zhidao.baidu.com/link?url=UyNCB4lHhQ9xCy-QInSyVRGHoWKxWy1h6GP8g688OFy8099Bz9XcrbEf_xIjz4V2_kc4XZpaBinrMea3ghoFv_

原文地址:https://www.cnblogs.com/gogood/p/3878691.html