You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solution/0100-0199/0178.Rank Scores/README.md
+10-10
Original file line number
Diff line number
Diff line change
@@ -66,9 +66,7 @@ Scores 表:
66
66
67
67
<!-- 这里可写通用的实现逻辑 -->
68
68
69
-
<!-- tabs:start -->
70
-
71
-
### **MySQL8**
69
+
**方法一:使用窗口函数 `DENSE_RANK()`**
72
70
73
71
使用 `DENSE_RANK()` 函数,语法如下:
74
72
@@ -86,20 +84,22 @@ DENSE_RANK() OVER (
86
84
87
85
与 `RANK()` 函数不同,`DENSE_RANK()` 函数始终返回连续的排名值。
88
86
89
-
题解如下:
87
+
**方法二:变量**
88
+
89
+
MySQL 8 开始才提供了 `ROW_NUMBER()`,`RANK()`,`DENSE_RANK()` 等[窗口函数](https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html),在之前的版本,可以使用变量实现类似的功能。
90
+
91
+
<!-- tabs:start -->
92
+
93
+
### **SQL**
90
94
91
95
```sql
92
96
# Write your MySQL query statement below
93
97
SELECT
94
-
Score,
95
-
DENSE_RANK() OVER (ORDER BYScoreDESC) AS'Rank'
98
+
score,
99
+
DENSE_RANK() OVER (ORDER BYscoreDESC) AS'rank'
96
100
FROM Scores;
97
101
```
98
102
99
-
### **MySQL5**
100
-
101
-
MySQL 8 开始才提供了 `ROW_NUMBER()`,`RANK()`,`DENSE_RANK()` 等[窗口函数](https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html),在之前的版本,可以使用变量实现类似的功能:
Copy file name to clipboardexpand all lines: solution/0100-0199/0178.Rank Scores/README_EN.md
+10-8
Original file line number
Diff line number
Diff line change
@@ -64,7 +64,7 @@ Scores table:
64
64
65
65
<!-- tabs:start -->
66
66
67
-
### **MySQL8**
67
+
**Solution 1: Use `DENSE_RANK()`**
68
68
69
69
Use `DENSE_RANK()` to solve this problem.
70
70
@@ -75,20 +75,22 @@ DENSE_RANK() OVER (
75
75
)
76
76
```
77
77
78
-
Solution:
78
+
**Solution 2: Use variables**
79
+
80
+
MySQL only provides [window function](https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html) after version 8. In previous versions, variables can be used to achieve similar functions.
81
+
82
+
<!-- tabs:start -->
83
+
84
+
### **SQL**
79
85
80
86
```sql
81
87
# Write your MySQL query statement below
82
88
SELECT
83
-
Score,
84
-
DENSE_RANK() OVER (ORDER BYScoreDESC) AS'Rank'
89
+
score,
90
+
DENSE_RANK() OVER (ORDER BYscoreDESC) AS'rank'
85
91
FROM Scores;
86
92
```
87
93
88
-
### **MySQL5**
89
-
90
-
MySQL only provides [window function](https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html) after version 8. In previous versions, variables can be used to achieve similar functions:
0 commit comments