当前位置:网站首页>ROW_NUMBER()、RANK()、DENSE_RANK区别
ROW_NUMBER()、RANK()、DENSE_RANK区别
2022-07-02 13:03:00 【牧码文】
ROW_NUMBER()、RANK()、DENSE_RANK区别
ROW_NUMBER():排序,不会有重复的排序数值。对于相等的两个数字,排序序号不一致
| 数值 | 排序序号 |
|---|---|
| 1 | 1 |
| 1 | 2 |
| 2 | 3 |
select
id,
row_number()
over(order by id) rn
from
data
DENSE_RANK():排序,可有重复值。对于相等的两个数字,排序序号一致
| 数值 | 排序序号 |
|---|---|
| 1 | 1 |
| 1 | 1 |
| 2 | 2 |
select
id,
dense_rank()
over(order by id) rn
from
data
RANK():排序,可有重复值。对于相等的两个数字,排序序号一致,但是总数会减少
| 数值 | 排序序号 |
|---|---|
| 1 | 1 |
| 1 | 1 |
| 2 | 3 |
select
id,
rank()
over(order by id) rn
from
data
如果窗口中over()无排序字段,那么结果如何?
select
id,
rank()
over()
from
data
| 数值 | 排序序号 |
|---|---|
| 1 | 1 |
| 1 | 1 |
| 2 | 1 |
如果窗口中over()无排序字段,使用的是row_number()排序,结果如何?
select
id,
row_number()
over()
from
data
| 数值 | 排序序号 |
|---|---|
| 1 | 1 |
| 2 | 2 |
| 1 | 3 |
这种现象的原因:
在over()窗口中,所有的数值排序都是一样的。对于rank因为允许重复,所以全为1,而row_number()不会有重复的排序序号,所以会为1,2,3,4,等,但是每次排序的结果都是不同的。
边栏推荐
- Song of cactus - throwing stones to ask the way (3)
- MySQL min() finds the minimum value under certain conditions, and there are multiple results
- Usage of group by
- The light of ideal never dies
- Add user-defined formula (time sharing t+0) to mobile app access as an example
- Maui learning road (III) -- in depth discussion of winui3
- 绝对真理和相对真理思考
- 去除router-link中的下划线
- 2022最新最详细必成功的在Vscode中设置背景图、同时解决不受支持的问题
- 理想之光不灭
猜你喜欢

Sim2real environment configuration tutorial

数据安全产业系列沙龙(三)| 数据安全产业标准体系建设主题沙龙

SSM integration exception handler and project exception handling scheme

忆当年高考|成为程序员的你,后悔了吗?

Memory alignment of structure

Pandora IOT development board learning (RT thread) - Experiment 2 RGB LED experiment (learning notes)

一文读懂AGV的关键技术——激光SLAM与视觉SLAM的区别

2022最新最详细必成功的在Vscode中设置背景图、同时解决不受支持的问题

MySQL calculates the data within the longitude and latitude range

Write your own CPU Chapter 11 - learning notes
随机推荐
What is the difference between self attention mechanism and fully connected graph convolution network (GCN)?
Sqlserver queries which indexes are underutilized
Aujourd'hui dans l'histoire: Alipay lance le paiement par code à barres; La naissance du père du système de partage du temps; La première publicité télévisée au monde...
Seal Library - installation and introduction
死锁的条件及解决方法
Practice of constructing ten billion relationship knowledge map based on Nebula graph
Recalling the college entrance examination and becoming a programmer, do you regret it?
Dimension table and fact table in data warehouse
By asp Net core downloads files according to the path exception
处理gzip: stdin: not in gzip formattar: Child returned status 1tar: Error is not recoverable: exitin
数学分析_笔记_第5章:一元微分学
HMS core machine learning service helps zaful users to shop conveniently
中国信通院《数据安全产品与服务图谱》,美创科技实现四大板块全覆盖
MySQL min() finds the minimum value under certain conditions, and there are multiple results
2022 the latest and most detailed will successfully set the background image in vscade and solve unsupported problems at the same time
Recommended practice sharing of Zhilian recruitment based on Nebula graph
The median salary of TSMC's global employees is about 460000, and the CEO is about 8.99 million; Apple raised the price of iPhone in Japan; VIM 9.0 releases | geek headlines
外企高管、连续创业者、瑜伽和滑雪高手,持续迭代重构的程序人生
2020.4.12 byte written test questions B DP D monotone stack
Does bone conduction earphone have external sound? Advantages of bone conduction earphones