test,有如下两个字段
id type category
1 不合格 电器
2 不确定 电器
3 不确定 手机
4 合格 手机
5 合格 飞机
6 不确定 飞机
7 合格 飞机
要生成如下形式报表
Category 合格 不合格 不确定 总数
电器 0 1 1 2
飞机 2 0 1 3
手机 1 0 1 2
总数 3 1 3 7
请用一条sql语句完成
select
Category=isnull(Category,'总数'),
合格=sum(case Type when '合格'then 1 else 0 end),
不合格=sum(case Type when '不合格'then 1 else 0 end),
不确定=sum(case Type when '不确定'then 1 else 0 end),
总数=sum(1)
from Test
group by category with rollup