oracle内置函数
来源:互联网 发布:淘宝led散热片 编辑:程序博客网 时间:2024/06/16 13:12
1.Oracle 分析函数——CUBE , ROLLUP
功能描述:
如果是 ROLLUP(A, B, C) 的话, GROUP BY 顺序
(A 、 B 、 C)
(A 、 B)
(A)
最后对全表进行 GROUP BY 操作。
如果是 GROUP BY CUBE(A, B, C) , GROUP BY 顺序
(A 、 B 、 C)
(A 、 B)
(A 、 C)
(A) ,
(B 、 C)
(B)
(C) ,
最后对全表进行 GROUP BY 操作。
2.分析函数——GROUPING
Rollup(部门,工作岗位) sum(每人的工资)
当部门的GROUPING为0,工作岗位的GROUPING也为0时,说明是公司发的总工资,此时放公司总计
当部门的GROUPING为0,工作岗位的GROUPING也为1时,说明是部门发的总工资,此时放部门小记
当部门的GROUPING为1,工作岗位的GROUPING也为1时,显示的是某部门某职位的工资和计
SQL> SELECT department_id DEPTID, job_id JOB,
2 SUM(salary),
3 GROUPING(department_id) GRP_DEPT,
4 GROUPING(job_id) GRP_JOB
5 FROM employees
6 GROUP BY ROLLUP(department_id, job_id);
3.GROUPING SETS与GROUPING的作用是不同的
Oracle服务器计算GROUPING SETS子句中所有的组并将结果通过UNION ALL组合成一个结果集.GROUPING SETS的效果:1.只需要访问一次基表.2.不需要写很复杂的UNION语句.
SELECT department_id, job_id, null manager_id,avg(salary)
FROM employees
GROUP BY (department_id,job_id)
UNION ALL
SELECT null department_id, job_id, manager_id,avg(salary)
FROM employees
GROUP BY (job_id,manager_id)
等同于
SQL> set autotrace on
SQL> SELECT department_id, job_id,
2 manager_id,avg(salary)
3 FROM employees
4 GROUP BY GROUPING SETS ((department_id,job_id), (job_id,manager_id));
·查询各学生科目为Oracle排名(简单排名)
select sc.s_id,sc.s_name,sub_name,sc.score,
rank() over (order by score desc) 名次
from t_score sc
where sub_name='Oracle'
·查询各学生各科排名(分区排名,分区非连续排名)
select sc.s_id,sc.s_name,sub_name,sc.score,
rank() over
(partition by sub_name order by score desc) 名次
from t_score sc
·查询各学生科目为Oracle排名(简单排名)
select sc.s_id,sc.s_name,sub_name,sc.score,
rank() over (order by score desc) 名次
from t_score sc
where sub_name='Oracle'
·查询各科前2名(分区排名)
·类似:新闻表,求栏目点击率在前3位的新闻。
商品表,求各类别销售额在前10位的商品。
select * from (
select sc.s_id,sc.s_name,sub_name,sc.score,
dense_rank() over
(partition by sub_name order by score desc) 名次
from t_score sc
) x
where x.名次<=2
·查询各学生科目为Oracle排名(简单排名)
select sc.s_id,sc.s_name,sub_name,sc.score,
rank() over (order by score desc) 名次
from t_score sc
where sub_name='Oracle'
- ORACLE内置函数大全
- ORACLE内置函数大全
- Oracle SQL内置函数
- ORACLE内置函数大全
- Oracle常用内置函数
- oracle内置函数大全
- oracle常用内置函数
- Oracle SQL 内置函数
- Oracle 内置SQL函数
- Oracle sql内置函数
- ORACLE 内置函数
- ORACLE内置函数大全
- Oracle 内置函数
- oracle 内置函数总结
- ORACLE内置函数
- ORACLE常用内置函数
- oracle内置函数
- 二.oracle内置函数
- mongodb常用命令
- python中文件基本操作
- keilc 4 编译出现的几个错误解决
- QT5.9 在线程中导出EXCLE报 CoCreateInstance failure (尚未调用 CoInitialize) 解决办法
- CFGym 101002C 状压DP
- oracle内置函数
- python之Flask(一)
- 【LeetCode】572. Subtree of Another Tree
- HDU
- 【腾讯笔试】满二叉排序树中查找三个节点的最小子树的根节点
- linux命令-sed命令使用(1)
- python中mysql基本操作
- MongoDB C++开发环境搭建
- 分布式消息系统:Kafka