select distinct(单位),COUNT(单位) as 类型数量,
sum(case when 类型=1 then 1 else 0 end) as 类型为1 ,
sum(case when 类型=2 then 1 else 0 end) as 类型为2,
sum(case when 类型=3 then 1 else 0 end) as 类型为3
from sh1
group by 单位
已测试,结果:
a2110
b3111
c1010
也祝福您身体健康,多金多福 ,快采纳,哈哈!
select 单位,
SUM(case 类型 when '1' then 1 else 0 end) as 类型为1,
SUM(case 类型 when '2' then 1 else 0 end) as 类型为2,
SUM(case 类型 when '3' then 1 else 0 end) as 类型为3
from 表A GROUP BY 单位