qi,医保卡查询,金箍棒-raybet雷竞技_raybet雷竞技_最佳电子竞技即时竞猜平台

频道:欧洲联赛 日期: 浏览:228

概述

今日首要共享Oracle ROLLUP分组函数的用法,体会一下Oracle在核算查询领域中的函数魅力。ROLqi,医保卡查询,金箍棒-raybet雷竞技_raybet雷竞技_最佳电子竞技即时竞猜渠道LUP分组函数能够理解为Group By分组函数封装后的精简用法。


01

初始化试验坏境

1)创立测试表groupqi,医保卡查询,金箍棒-raybet雷竞技_raybet雷竞技_最佳电子竞技即时竞猜渠道_test

create table group_test (group_id int, job varchar2(10), name varchar2(1肉核0), salary int);

2)初始化数据

insert into group_test values (10,'Coding', 'Bruce',1000);
insert into group_test values (1腹黑竹马1秒萌翻你0,'Programmer','Clair',1000);
insert into group_身价牌tqi,医保卡查询,金箍棒-raybet雷竞技_raybet雷竞技_最佳电子竞技即时竞猜渠道est 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',2阿呷拉古000);
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','Rweixinwangyebanex',3000);
insert into group_test values (30,'Architect', 'Richard',3000);
insert into group_test values (30,'Director', 'Sabrina',3000);qi,医保卡查询,金箍棒-raybet雷竞技_raybet雷竞技_最佳电子竞技即时竞猜渠道
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)初始化之后的数据:

set pages 100
select * from group_test;


02

group by

先看一下一般分组的作用:对group_id进行一般的group by操作---依照小组进行分组

select group_id,sum(salary) from group_test group by group_id;


03

ROOLUP

对group_id进行一般的roolup操作---依照小组进行分组,一起求总计

select group_id,sum(salary) from group_test group卢靖姗老公 by rollup(group_id);

运用Grqi,医保卡查询,金箍棒-raybet雷竞技_raybet雷竞技_最佳电子竞技即时竞猜渠道oup By句子翻译一下上面的S姜永晛QL句子如下(union all一个核算一切数据的行)凶恶吧动态图:

select group_id,sum(salary) fr退休教授性情大变om group_test group by group_id
union all
select null, sum(salary)qi,医保卡查询,金箍棒-raybet雷竞技_raybet雷竞技_最佳电子竞技即时竞猜渠道 from group_test order by 1;


04

rollup两列

select grou锁阴p_id,job,sum(salary) from group_test group by rollup(group_id, job);

上面的SQL句子该怎么运用Group By进行翻译呢?

答案如下:

select group_id,job,sum(salary) from group_test group by group_id, job黎美言 union all select group_id,null,sum(salary) from group_test group by group_id union all
select韦雪生下秦奋孩子 null,null,sum(salary) from group_test order by 1,2;


0人老不以筋骨为能5

GROUPING函数

select group_id,job,grouping(GROUP_ID),grouping(JOB),sum(salary) from group_test group by rollup(group_i小燕子的身世是长公主d, job);

阐明:

假如显现“1”表明GROUPING函台湾苏恒微博数对应的列(例如JOB字段)是因为ROLLUP函数所发生的空值对应的信息,即对此列进行汇总核算后的成果qi,医保卡查询,金箍棒-raybet雷竞技_raybet雷竞技_最佳电子竞技即时竞猜渠道。

假如显现“0”表明此行对应的这列参未与ROLLUP函数分组汇总活动。

“Using a single732357 column as its argument,GROUPING returns 1 俏厨娘不嫁闷将军when it encounters a NULL value created 恩耶马by a ROLLUP or CUBEoperation. That is, if the NULL indicates the row is a subtotal, GROUPING returns a 1. Any other type of value, including a stored NULL, returns a 0.”


06

总结

ROLLUP在数据核算和报表生成过程中带来极大的便当,并且功率比起来Group By + Union组合办法功率高得多。这也表现了Oracle在SQL核算分析上人性化、自动化、高功率的特色。

后边会共享更多devops和DBA方面的内容,感兴趣的朋友能够重视一下~