当前位置:网站首页>Oracle 分析函数 over 和MySQL 实现类似效果写法
Oracle 分析函数 over 和MySQL 实现类似效果写法
2022-06-11 16:30:00 【peach桃】
(1)分析函数:
rank ( ) over ( [query_partition_clause]order_by_clause )
dense_rank ( ) over([query_partition_clause] order_by_clause )
rownumber ( ) over ([query_partition_clause]order_by_clause )
可实现按指定的字段分组排序,对于相同分组字段的结果集进行排序,其中partition by 为分组字段,order by 指定排序字段
over不能单独使用,要和分析函数:rank(),dense_rank(),row_number()等一起使用
(2)Oracle分析函数与聚合函数的区别:
分析函数用于计算基于组的某种聚合值,它和聚合函数的不同之处是对于每个组返回多行,而聚合函数对于每个组只返回一行。(3)列子
求分组后排名情况可,例:
select* from
(
select a.*,row_number() over(PARTITION BY project_id order by task_Assign_time desc) asrId
fromrate_task_info a
)
where rId=1
(4)MySQL实现例子
SELECT * from(
select @rownum:[email protected]+1 rownum,a.*,
if(@objno=a.project_id or (@objno is null and a.project_id is null),
@rank:[email protected]+1,
@rank:=1) as row_number,
@objno:=a.project_id
from(SELECT * from rate_task_info where current_node=700 order by project_id,task_Assign_timedesc)a,
(select @rownum :=0,@objno:=null,@rank:=0)b
)t
where t.row_number=1;
边栏推荐
- 【剑指Offer】22.链表中倒数第K节点
- cocoapod只更新指定库(不更新索引)
- How unittest knows the execution time of each test case
- Laravel 8 uses passport for auth authentication and token issuance
- leetcode684. 冗余连接(中等)
- 2022 molten welding and thermal cutting work license and simulation examination
- Laravel 8 realizes database backup through task scheduling
- 485天,我远程办公的 21 条心得分享|社区征文
- 2022安全员-A证考试题模拟考试题库模拟考试平台操作
- Implementation of VGA protocol based on FPGA
猜你喜欢

After reading the book reading methods

信息收集常用工具及命令

tornado环境搭建及基本框架搭建——熟悉的hello world

Ruiji takeout project (III) employee management business development

Step 4 of installation in RF: an error is reported when installing the robotframework-selenium 2library

微服务连接云端Sentinel 控制台失败及连接成功后出现链路空白问题(已解决)

为什么芯片设计也需要「匠人精神」?

【pytest学习】pytest 用例执行失败后其他不再执行

laravel 监听模式

R1 Quick Open Pressure Vessel Operation test Library and Simulation Test in 2022
随机推荐
微信小程序时间戳转化时间格式+时间相减
What happened to the frequent disconnection of the computer at home
2022 molten welding and thermal cutting work license and simulation examination
Web page design example assignment -- Introduction to Henan cuisine (4 pages) web final assignment design web page_ Dessert and gourmet college students' web design homework finished product
[从零开始学习FPGA编程-17]:快速入门篇 - 操作步骤2-5- VerilogHDL硬件描述语言符号系统与程序框架(软件程序员和硬件工程师都能看懂)
MSDN download win11 method, simple and easy to operate
one hundred and twenty-three thousand one hundred and twenty-three
Detailed explanation of MySQL binlog log and master-slave replication
After reading the book reading methods
DHCP protocol instantiation analysis
2022 R1 quick opening pressure vessel operation test question bank and simulation test
A team of heavyweights came to the "digital transformation" arena of CLP Jinxin ice and snow sports
C starts an external EXE file and passes in parameters
2022年R1快開門式壓力容器操作考試題庫及模擬考試
What if you can't access the desktop after the computer is turned on
Pyqt5 enables the qplaintextedit control to support line number display
基于udp端口猜测的内网穿透
基于ssm框架实现的企业进销存管理系统【源码+数据库+毕设】
If you want to learn ArrayList well, it is enough to read this article
2022高压电工特种作业证考试题库及在线模拟考试