create table tb(dq varchar(20),mj float) insert into tb(dq,mj)
select 'A',10 from dual
union all
select 'B',6 from dual
union all
select 'C',69 from dual
union all
select 'A',30 from dual
union all
select 'B',40 from dual
select
dq as 所属地区,
sum(case when mj<10 then 1 else 0 end) as "10以下",
sum(case when mj>=10 and mj<20 then 1 else 0 end) as "10~20",
sum(case when mj>=20 and mj<50 then 1 else 0 end) as "20~50",
sum(case when mj>=50 then 1 else 0 end) as "50以上"
from tb
group by dq/*
所属地区 "10以下" "10~20" "20~50" "50以上"
1 A 0 1 1 0
2 B 1 0 1 0
3 C 0 0 0 1
*/
select 'A',10 from dual
union all
select 'B',6 from dual
union all
select 'C',69 from dual
union all
select 'A',30 from dual
union all
select 'B',40 from dual
select
dq as 所属地区,
sum(case when mj<10 then 1 else 0 end) as "10以下",
sum(case when mj>=10 and mj<20 then 1 else 0 end) as "10~20",
sum(case when mj>=20 and mj<50 then 1 else 0 end) as "20~50",
sum(case when mj>=50 then 1 else 0 end) as "50以上"
from tb
group by dq/*
所属地区 "10以下" "10~20" "20~50" "50以上"
1 A 0 1 1 0
2 B 1 0 1 0
3 C 0 0 0 1
*/
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货