当前位置:网站首页>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;
边栏推荐
- Simulated 100 questions and simulated examination for main principals of hazardous chemical business units in 2022
- 2022 high voltage electrician special operation certificate examination question bank and online simulation examination
- 完整的测试流程【杭州多测师】【杭州多测师_王sir】
- [sword finger offer] 21 Adjust array order so that odd numbers precede even numbers
- VLAN partition and routing between VLANs
- web网页设计实例作业 ——河南美食介绍(4页) web期末作业设计网页_甜品美食大学生网页设计作业成品
- RSP:遥感预训练的实证研究
- 数据库全量SQL分析与审计系统性能优化之旅
- 时序预测 | MATLAB实现RBF径向基神经网络时间序列未来多步预测
- 2022g1 industrial boiler stoker test questions and simulation test
猜你喜欢

1267_FreeRTOS启动第一个任务接口prvPortStartFirstTask实现分析

Ruiji takeout project (III) employee management business development

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

leetcode684. Redundant connection (medium)
Detailed explanation of MySQL binlog log and master-slave replication

2022安全员-A证考试题模拟考试题库模拟考试平台操作

2022 high voltage electrician special operation certificate examination question bank and online simulation examination

2022年R1快開門式壓力容器操作考試題庫及模擬考試

整了20张高清数据分析全知识地图,强烈建议收藏!

Go quick start of go language (I): the first go program
随机推荐
Pytest测试框架基础篇
tornado环境搭建及基本框架搭建——熟悉的hello world
2022 molten welding and thermal cutting work license and simulation examination
问题 AC: 中国象棋中的跳马问题
Pytest test framework Basics
微信小程序时间戳转化时间格式+时间相减
leetcode-141.环形链表
2022安全员-A证考试题模拟考试题库模拟考试平台操作
DHCP protocol instantiation analysis
回归预测 | MATLAB实现RBF径向基神经网络多输入单输出
Can I eat meat during weight loss? Will you get fat?
【opencvsharp】斑点检测 条码解码 图像操作 图像旋转/翻转/缩放 透视变换 图像显示控件 demo笔记
利用 MATLAB 和 DCRAW 处理数码相机 RAW 文件的完整流程
cocoapod只更新指定库(不更新索引)
Go语言之Go 快速入门篇(一):第一个 Go 程序
【剑指Offer】22.链表中倒数第K节点
1267_ FreeRTOS starts the first task interface prvportstartfirsttask implementation analysis
减肥期间可以吃肉吗?会胖吗?
After reading the book reading methods
Leetcode 1974. 使用特殊打字机键入单词的最少时间(可以,一次过)