oracle 根据数值范围分组 (group by )

阅读更多

create table aa_test
(
name varchar2(10),
num varchar2(10)
);



insert into aa_test values('admin1','1');
insert into aa_test values('admin1','2');
insert into aa_test values('admin1','11');
insert into aa_test values('admin1','12');
insert into aa_test values('admin1','22');


select a.*,a.rowid from aa_test a

--开始分组
select num ,count(1) from
(
select case
       when num between 1 and 10 then '1到10分钟'
       when num between 11 and 20 then '11到20分钟'
       when num between 21 and 30 then '21到30分钟'
       end num
from aa_test
)
group by num

你可能感兴趣的:(oracle)