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.
Example
Table: ScoreId Score1 3.402 3.553 5.004 3.755 4.006 3.55
Output:
Output :score Rank5.00 14.00 23.75 33.55 43.55 43.40 5
Approach
Mysql
SELECTScore as Score,DENSE_RANK() OVER(ORDER BY Score DESC) as 'Rank'FROMScores;
Oracle
SELECTScore as Score,DENSE_RANK() OVER(ORDER BY Score DESC) as RankFROMScores;
No comments:
Post a Comment