本文通过演示给出Oracle ROLLUP分组函数的用法,体验一下Oracle在统计查询领域中的函数魅力。ROLLUP分组函数可以理解为Group By分组函数封装后的精简用法,这里同时给出ROLLUP的Group By的改写思路。
1.初始化实验坏境
1)创建测试表group_test
SECOOLER@ora11g> create table group_test (group_id int, job varchar2(10), name varchar2(10), salary int);
Table created.
2)初始化数据
insert into group_test values (10,‘Coding’, ‘Bruce’,1000);
insert into group_test values (10,‘Programmer’,‘Clair’,1000);
insert into group_test values (10,‘Architect’, ‘Gideon’,1000);
insert into group_test values (10,‘Director’, ‘Hill’,1000);
insert into group_test values (20,‘Coding’, ‘Jason’,2000);
insert into group_test values (20,‘Programmer’,‘Joey’,2000);
insert into group_test values (20,‘Architect’, ‘Martin’,2000);
insert into group_test values (20,‘Director’, ‘Michael’,2000);
insert into group_test values (30,‘Coding’, ‘Rebecca’,3000);
insert into group_test values (30,‘Programmer’,‘Rex’,3000);
insert into group_test values (30,‘Architect’, ‘Richard’,3000);
insert into group_test values (30,‘Director’, ‘Sabrina’,3000);
insert into group_test values (40,‘Coding’, ‘Samuel’,4000);
insert into group_test values (40,‘Programmer’,‘Susy’,4000);
insert into group_test values (40,‘Architect’, ‘Tina’,4000);
insert into group_test values (40,‘Director’, ‘Wendy’,4000);
commit;
3)初始化之后的数据情况如下:
SECOOLER@ora11g> set pages 100
SECOOLER@ora11g>