当前位置:网站首页>ROW_ NUMBER()、RANK()、DENSE_ Rank difference
ROW_ NUMBER()、RANK()、DENSE_ Rank difference
2022-07-02 16:27:00 【Mu code text】
ROW_NUMBER()、RANK()、DENSE_RANK difference
ROW_NUMBER(): Sort , There will be no duplicate sorting values . For two equal numbers , Sequence number is inconsistent
The number | Sort sequence number |
---|---|
1 | 1 |
1 | 2 |
2 | 3 |
select
id,
row_number()
over(order by id) rn
from
data
DENSE_RANK(): Sort , There may be duplicate values . For two equal numbers , The sequence number is consistent
The number | Sort sequence number |
---|---|
1 | 1 |
1 | 1 |
2 | 2 |
select
id,
dense_rank()
over(order by id) rn
from
data
RANK(): Sort , There may be duplicate values . For two equal numbers , The sequence number is consistent , But the total will decrease
The number | Sort sequence number |
---|---|
1 | 1 |
1 | 1 |
2 | 3 |
select
id,
rank()
over(order by id) rn
from
data
If in the window over() No sort field , So what's the result ?
select
id,
rank()
over()
from
data
The number | Sort sequence number |
---|---|
1 | 1 |
1 | 1 |
2 | 1 |
If in the window over() No sort field , It uses row_number() Sort , What is the result? ?
select
id,
row_number()
over()
from
data
The number | Sort sequence number |
---|---|
1 | 1 |
2 | 2 |
1 | 3 |
The reason for this phenomenon :
stay over() Window , All numerical orders are the same . about rank Because repetition is allowed , So it's all 1, and row_number() There will be no duplicate sort sequence number , So it will 1,2,3,4, etc. , But the result of each sorting is different .
边栏推荐
- MySQL min() finds the minimum value under certain conditions, and there are multiple results
- Figure database | Nepal graph v3.1.0 performance report
- 去除router-link中的下划线
- HMS core machine learning service helps zaful users to shop conveniently
- 仙人掌之歌——投石问路(3)
- Recommended practice sharing of Zhilian recruitment based on Nebula graph
- After the win10 system is upgraded for a period of time, the memory occupation is too high
- Leetcode --- longest public prefix
- Practice of constructing ten billion relationship knowledge map based on Nebula graph
- Boot 事务使用
猜你喜欢
After the win10 system is upgraded for a period of time, the memory occupation is too high
通过两级网关设计来路由服务网格流量
[fluent] dart data type number type (DART file creation | num type | int type | double type | num related API)
Mysql database mysqldump why there is no statement to create a database
Rock PI Development Notes (II): start with rock PI 4B plus (based on Ruixing micro rk3399) board and make system operation
MySQL min() finds the minimum value under certain conditions, and there are multiple results
Mathematical analysis_ Notes_ Chapter 6: Riemann integral of univariate function
Does bone conduction earphone have external sound? Advantages of bone conduction earphones
idea 公共方法抽取快捷键
2022最新最详细必成功的在Vscode中设置背景图、同时解决不受支持的问题
随机推荐
图书管理系统(山东农业大学课程设计)
去除router-link中的下划线
dried food! Understand the structural vulnerability of graph convolution networks
By asp Net core downloads files according to the path exception
Invalid bound statement (not found) solution summary
虚假的暑假
结构体的内存对齐
[solution] educational codeforces round 82
JS learning notes - data types
Set the background picture in the idea (ultra detailed)
Foreign enterprise executives, continuous entrepreneurs, yoga and skiing masters, and a program life of continuous iteration and reconstruction
Everyone Xinfu builds: a one-stop intelligent business credit service platform
mysql min() 求某条件下最小的值出现多个结果
七一献礼:易鲸捷 “百日会战”完美收官 贵阳银行数据库提前封板
数学分析_笔记_第5章:一元微分学
SQLServer查询哪些索引利用率低
Practice of constructing ten billion relationship knowledge map based on Nebula graph
mysql 计算经纬度范围内的数据
由ASP.NET Core根据路径下载文件异常引发的探究
2022 the latest and most detailed will successfully set the background image in vscade and solve unsupported problems at the same time