select 单位,count(*) from (select
( case
when substr(DEPT_CODE,0,2) = 'CT' THEN DEPT_CODE
when substr(DEPT_CODE,0,2) = 'PF' THEN DEPT_CODE
when substr(DEPT_CODE,0,2) = 'CQ' THEN DEPT_CODE
when substr(DEPT_CODE,0,2) = 'TY' THEN DEPT_CODE
when substr(DEPT_CODE,0,2) = 'BH' THEN DEPT_CODE
else '其他'
end) as 单位 from XQGL_PLAN_REQ)
group by 单位 order by 单位
运行结果如下