select t.分类,count(t.处理时长) from (
select case when 处理时长>180 then '180以上'
when 处理时长>90 then '90-180'
when 处理时长>60 then '60-90'
when 处理时长>30 then '30-60'
else '30及以下' end as 分类,
处理时长
from 表
) t
group by t.分类
------------------修改后-------------------
select
t.分类,
count(t.分类) as 个数
from (
SELECT
case when DATEDIFF(day, field0012, GETDATE())>180 then '180以上'
when DATEDIFF(day, field0012, GETDATE())>90 then '90-180'
when DATEDIFF(day, field0012, GETDATE())>60 then '60-90'
when DATEDIFF(day, field0012, GETDATE())>30 then '30-60'
else '30及以下' end as 分类
FROM formmain_1141
WHERE finishedflag = '0'
AND field0047 = 'PVA01'
) t
group by t.分类