当前位置:网站首页>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;
边栏推荐
猜你喜欢

C# 启动一个外部exe文件,并传入参数

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

项目经理如何击退被工作汇报支配的恐惧感?

After reading the book reading methods

Heartless sword English Chinese bilingual poem 001 Spring outing

What if you can't access the desktop after the computer is turned on

虚拟局域网划分与虚拟局域网间路由(VLAN)

Differences between list and set access elements

JVM 的组成

Implementation of VGA protocol based on FPGA
随机推荐
R1 Quick Open Pressure Vessel Operation test Library and Simulation Test in 2022
leetcode-141. Circular linked list
2022高压电工特种作业证考试题库及在线模拟考试
2022起重机司机(限桥式起重机)考试题模拟考试题库及模拟考试
laravel 2020-01-01T00:00:00.000000Z 日期转化
laravel 8 使用passport 进行Auth验证及颁发token
What is a generic? Why use generics? How do I use generics? What about packaging?
web网页设计实例作业 ——河南美食介绍(4页) web期末作业设计网页_甜品美食大学生网页设计作业成品
Leetcode 1974. 使用特殊打字机键入单词的最少时间(可以,一次过)
Zhenxiang, Huawei gives n+1 for voluntary resignation
MSDN download win11 method, simple and easy to operate
最近7天,最近10天,最近90天时间处理逻辑
时间复杂度与空间复杂度解析
laravel 8 通过 任务调度 实现 数据库备份
什么是泛型?为什么要使用泛型?泛型怎么用?那包装类呢?
unittest 如何知道每个测试用例的执行时间
大龄码农从北京到荷兰的躺平生活
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
Laravel 8 uses passport for auth authentication and token issuance
C# 启动一个外部exe文件,并传入参数