oracle下的OVER(PARTITION BY)函数介绍
发布日期:2025-04-30 00:05:16
浏览次数:10
分类:精选文章
本文共 3168 字,大约阅读时间需要 10 分钟。
Oracle OVER??????
?Oracle?????OVER?????????????????????????????????????Partition By??????????Order By????????????????OVER???????????????????????????????
1. OVER???????
OVER??????????
SELECT column_name, sum(column_name) OVER(partition_by_clause order_by_clause) FROM table_name;
??
SELECT name, class, s, sum(s) OVER(partition_by class order_by s desc) mm FROM t2WHERE mm = 1;
??
| name | class | s | mm |
|---|---|---|---|
| dss | 1 | 95 | 190 |
| ffd | 1 | 95 | 190 |
| gds | 2 | 92 | 92 |
| cfe | 2 | 74 | 166 |
| gf | 3 | 99 | 198 |
| ddd | 3 | 99 | 198 |
| 3dd | 3 | 78 | 276 |
| asdf | 3 | 55 | 331 |
| asdf | 3 | 45 | 376 |
2. Partition By?Order By???
OVER???????Partition By?Order By????Partition By???????????????Order By????????????????
??1?Partition By deptno Order By salary
SELECT deptno, ename, sal, rank() OVER(partition_by deptno order_by sal) r, (SELECT COUNT(1) n FROM emp GROUP BY deptno) bFROM empWHERE deptno IN (30, 60);
??2?Partition By class Order By s desc
SELECT class, s, rank() OVER(partition_by class order_by s desc) mm FROM t2WHERE mm = 1;
3. Range?Rows???
OVER????Range?Rows???????????Range?????????Rows????N??
???Range between 5 preceding and 5 following
SELECT name, class, s, sum(s) OVER(order_by s range between 5 preceding and 5 following) mm FROM t2WHERE mm = 1;
???Rows between 2 preceding and 2 following
SELECT name, class, s, sum(s) OVER(order_by s rows between 2 preceding and 2 following) mm FROM t2WHERE mm = 1;
4. Unbounded Preceding and Following
?Range?Rows???unbounded????????????????
???Unbounded preceding and following
SELECT opr_id, res_type, first_value(res_type) OVER(partition_by opr_id order_by res_type) low, last_value(res_type) OVER(partition_by opr_id order_by res_type rows BETWEEN unbounded preceding AND unbounded following) highFROM rm_circuit_routeWHERE opr_id IN ('000100190000000000021311', '000100190000000000021355', '000100190000000000021339')ORDER BY opr_id; 5. rank()?dense_rank()?percent_rank()
rank()
rank()????????????????????????
dense_rank()
dense_rank()???rank()????????????????
percent_rank()
percent_rank()????????????????????
???percent_rank
SELECT deptno, ename, sal, (a.r-1)/(n-1) pr1, percent_rank() OVER(partition_by deptno order_by sal) pr2FROM ( SELECT deptno, ename, sal, rank() OVER(partition_by deptno order_by sal) r FROM emp WHERE deptno IN (30, 60)) a,(SELECT deptno, COUNT(1) n FROM emp GROUP BY deptno) bWHERE a.deptno = b.deptno;
6. cume_dist()?percentile_cont()
cume_dist()
cume_dist()?????????????CDF???????????????????
percentile_cont()
percentile_cont()??????????????????
???percentile_cont(0.7)
SELECT ename, sal, deptno, percentile_cont(0.7) within group(order_by sal) over(partition_by deptno) "Percentile_Cont", percent_rank() OVER(partition_by deptno order_by sal) "Percent_Rank"FROM empWHERE deptno IN (30, 60);
7. PERCENTILE_DISC()
PERCENTILE_DISC()????????????????
???
SELECT ename, sal, deptno, percentile_disc(0.7) within group(order_by sal) over(partition_by deptno) "Percentile_Disc", cume_dist() over(partition_by deptno order_by sal) "Cume_Dist"FROM empWHERE deptno IN (30, 60);
???????????Oracle?OVER??????????????????????????????????????????????????
发表评论
最新留言
路过,博主的博客真漂亮。。
[***.116.15.85]2026年06月09日 11时48分34秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
PHP将图片转换成base64格式(优缺点)
2023-03-01
php将多个值的数组去除重复元素
2023-03-01
php局域网上传文件_PHP如何通过CURL上传文件
2023-03-01
PHP工具插件大全
2023-03-01
php布尔值的++
2023-03-01
PHP常量、变量作用域详解(一)
2023-03-01
PHP应用目录结构设计
2023-03-01
PHP应用程序连接MSQL数据库Demo(附crud程序)
2023-03-01
PHP应用程序连接Oracle数据库Demo(附Oracle客户端安装文件)
2023-03-01
PHP开发api接口安全验证
2023-03-01
PHP开发规范PSR
2023-03-01
PHP开发遇到错误0001
2023-03-01
rabbitmq guestguest用户不能远程登录
2023-03-01
php异常处理
2023-03-01
PHP引入了泛型和集合两大重要特性,大大改善 PHP 代码的可维护性和可读性
2023-03-01
PHP引擎php.ini参数优化
2023-03-01
PHP引用(&)使用详解
2023-03-01
php引用及垃圾回收
2023-03-01
php当前时间的集中写法
2023-03-01