178. Rank Scores - database - 178. Rank Scores (Oracle)

题目链接    https://leetcode.com/problems/rank-scores/description/

题意:对所有的分数按照降序进行排序,查询出分数和排名,排名相同的输出相同名次

此种解法在leetcode中未通过,看错误提示,好像是数据的精确度问题,不知道为什么。

 附上一个通过的(mysql):https://blog.csdn.net/travel_1/article/details/51589706

思路:

1、首先查出 不重复的所有分数排名

select distinct Score from Scores order by Score desc

2、使用rownum标记处排名

select rownum rank,Score from 
	(select distinct Score from Scores order by Score desc)

3、左连接求出所有的成绩以及排名

  

select s1.Score,s2.rank from Scores s1 left join (select rownum rank,Score from (select distinct Score from Scores order by Score desc))s2 on s1.Score = s2.Score order by s1.Score desc

  

posted @ 2018-09-17 17:12  非我非非我  阅读(266)  评论(0编辑  收藏  举报