mysql rank的用法

阅读: 评论:0

mysql rank的用法

mysql rank的用法

在mysql数据库中 rank的用法的用法你知道吗?下面小编就跟你们详细介绍下在mysql数据库中 rank的用法的用法,希望对你们有用。

在mysql数据库中 rank的用法的用法如下:

Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ranking. Note that after a tie, the next ranking number should be the next consecutive integer value. In other words, there should be no "holes" between ranks.

?

1

2

3

4

5

6

7

8

9

10

+----+-------+

| Id | Score |

+----+-------+

| 1 | 3.50 |

| 2 | 3.65 |

| 3 | 4.00 |

| 4 | 3.85 |

| 5 | 4.00 |

| 6 | 3.65 |

+----+-------+

For example, given the above Scores table, your query should generate the following report (order by highest score):

?

1

2

3

4

5

6

7

8

9

10

+-------+------+

| Score | Rank |

+-------+------+

| 4.00 | 1 |

| 4.00 | 1 |

| 3.85 | 2 |

| 3.65 | 3 |

| 3.65 | 3 |

| 3.50 | 4 |

+-------+------+

题目解答:

?

1

2

3

4

5

6

7

8

9

10

# Write your MySQL query statement below

SELECT Scores.Score, COUNT(Ranking.Score) AS RANK

FROM Scores

, (

SELECT DISTINCT Score

FROM Scores

) Ranking

WHERE Scores.Score <= Ranking.Score

GROUP BY Scores.Id, Scores.Score

ORDER BY Scores.Score DESC;

本文发布于:2024-01-31 17:52:00,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170669472230298.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:mysql   rank
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23