当前位置:网站首页>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 .
边栏推荐
- JS learning notes - process control
- 死锁的条件及解决方法
- SSM整合-异常处理器及项目异常处理方案
- Memory alignment of structure
- 请问怎么在oracle视图中使用stustr函数
- Yyds dry inventory company stipulates that all interfaces use post requests. Why?
- 中国信通院《数据安全产品与服务图谱》,美创科技实现四大板块全覆盖
- 路由模式:hash和history模式
- MySQL calculates the data within the longitude and latitude range
- What is Amazon keyword index? The consequences of not indexing are serious
猜你喜欢

End time processing method of wechat v3native payment settings
![[fluent] dart data type string type (string definition | string splicing | string API call)](/img/7b/cc624aa33f45fbed0bbe354253158b.jpg)
[fluent] dart data type string type (string definition | string splicing | string API call)

Practice of constructing ten billion relationship knowledge map based on Nebula graph

Storage, reading and writing of blood relationship data of Nepal Graph & Data Warehouse

Set the background picture in the idea (ultra detailed)

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

JS learning notes - data types

去除router-link中的下划线

结构体的内存对齐

Yyds dry inventory method of deleting expired documents in batch
随机推荐
总结|机器视觉中三大坐标系及其相互关系
Sqlserver queries which indexes are underutilized
华为云服务器安装mysqlb for mysqld.service failed because the control process exited with error code.See “sys
AWS云主机扩容
Leetcode -- number of palindromes
win10系统升级一段时间后,内存占用过高
图书管理系统(山东农业大学课程设计)
Pandora IOT development board learning (RT thread) - Experiment 2 RGB LED experiment (learning notes)
Multi data source configuration code
[Yu Yue education] reference materials of sensing and intelligent control technology of Nanjing University of Technology
sim2real环境配置教程
Win11应用商店无法加载页面怎么办?Win11商店无法加载页面
mysql数据库mysqldump为啥没有创建数据库的语句
dried food! Understand the structural vulnerability of graph convolution networks
Huawei ECS installs mysqlb for mysqld service failed because the control process exited with error code. See “sys
Understand the key technology of AGV -- the difference between laser slam and visual slam
sql解决连续登录问题变形-节假日过滤
分析超700万个研发需求发现,这8门编程语言才是行业最需要的!
Write your own CPU Chapter 11 - learning notes
Idea public method extraction shortcut key