先对字段做个转换后进行汇总, 拿sql举个例子:
数据表AA如
ID name
1 a1
2 a2
3 a3
4 b1
5 b2
6 c
select namegroup, count(*) as total
from (
select id,
case when name in ('a1','a2','a3') then 'a' when name in ('b1','b2') then 'b' else name end as namegroup
from AA
) group by namegroup
出来结果是
a 3
b 2
c 1
数据表AA如
ID name
1 a1
2 a2
3 a3
4 b1
5 b2
6 c
select namegroup, count(*) as total
from (
select id,
case when name in ('a1','a2','a3') then 'a' when name in ('b1','b2') then 'b' else name end as namegroup
from AA
) group by namegroup
出来结果是
a 3
b 2
c 1
3 个回复
joeywen
赞同来自:
yangruideyang
赞同来自:
luqixinhe - 80后IT男
赞同来自: