select bg_severity,count(*) as row_count
from 表名 group by bg_severity
结果:
bg_severity row_count
1-低 xx
2-中 xx
1-高 xx
select sum(case when bg_severity = N'1-低' then 1 else 0 end) as [1-低],
sum(case when bg_severity = N'2-中' then 1 else 0 end) as [2-中],
sum(case when bg_severity = N'3-高' then 1 else 0 end) as [3-高]
from 表名
结果:
1-低 |2-中 |3-高
xx |xx | xx
select bg_severity,count(*) from 表名 group by bg_severity