43、数据库 case +group by
1、case + groupby
格式:
select xx,
when xx = xx then xxx
when xx = xx then xxx
when xx = xx then xxx
else xx
end as xx
from xx
group by xx
案例:
select case
when indexid = 1 then '人员主题类'
when indexid = 2 then '机构主题类'
when indexid = 3 then '资产主体类'
when indexid = 4 then '权利运行类'
when indexid = 5 then '生活服务类'
when indexid = 6 then '案件事件类'
when indexid = 7 then '出行信息类'
when indexid = 8 then '社会关系类'
else '其他'
end as NAME,
sum(table_quantity) AS data_count
from t_tableinfo
where isdel = '0' and indexid is not null
group by indexid
order by indexid
结果: