{ "data": { "question": { "questionId": "178", "questionFrontendId": "178", "categoryTitle": "Database", "boundTopicId": 1125, "title": "Rank Scores", "titleSlug": "rank-scores", "content": "

Table: Scores

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| id          | int     |\n| score       | decimal |\n+-------------+---------+\nid is the primary key for this table.\nEach row of this table contains the score of a game. Score is a floating point value with two decimal places.\n
\n\n

 

\n\n

Write an SQL query to rank the scores. The ranking should be calculated according to the following rules:

\n\n\n\n

Return the result table ordered by score in descending order.

\n\n

The query result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nScores table:\n+----+-------+\n| id | score |\n+----+-------+\n| 1  | 3.50  |\n| 2  | 3.65  |\n| 3  | 4.00  |\n| 4  | 3.85  |\n| 5  | 4.00  |\n| 6  | 3.65  |\n+----+-------+\nOutput: \n+-------+------+\n| score | rank |\n+-------+------+\n| 4.00  | 1    |\n| 4.00  | 1    |\n| 3.85  | 2    |\n| 3.65  | 3    |\n| 3.65  | 3    |\n| 3.50  | 4    |\n+-------+------+\n
\n", "translatedTitle": "分数排名", "translatedContent": "

表: Scores

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| id          | int     |\n| score       | decimal |\n+-------------+---------+\nId是该表的主键。\n该表的每一行都包含了一场比赛的分数。Score是一个有两位小数点的浮点值。\n
\n\n

 

\n\n

编写 SQL 查询对分数进行排序。排名按以下规则计算:

\n\n\n\n

按 score 降序返回结果表。

\n\n

查询结果格式如下所示。

\n\n

 

\n\n

示例 1:

\n\n
\n输入: \nScores 表:\n+----+-------+\n| id | score |\n+----+-------+\n| 1  | 3.50  |\n| 2  | 3.65  |\n| 3  | 4.00  |\n| 4  | 3.85  |\n| 5  | 4.00  |\n| 6  | 3.65  |\n+----+-------+\n输出: \n+-------+------+\n| score | rank |\n+-------+------+\n| 4.00  | 1    |\n| 4.00  | 1    |\n| 3.85  | 2    |\n| 3.65  | 3    |\n| 3.65  | 3    |\n| 3.50  | 4    |\n+-------+------+
\n", "isPaidOnly": false, "difficulty": "Medium", "likes": 923, "dislikes": 0, "isLiked": null, "similarQuestions": "[]", "contributors": [], "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"ruby\": false, \"bash\": false, \"swift\": false, \"golang\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"kotlin\": false, \"rust\": false, \"php\": false, \"typescript\": false, \"racket\": false, \"erlang\": false, \"elixir\": false}", "topicTags": [ { "name": "Database", "slug": "database", "translatedName": "数据库", "__typename": "TopicTagNode" } ], "companyTagStats": null, "codeSnippets": [ { "lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode" }, { "lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode" }, { "lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"148.2K\", \"totalSubmission\": \"245.2K\", \"totalAcceptedRaw\": 148155, \"totalSubmissionRaw\": 245153, \"acRate\": \"60.4%\"}", "hints": [], "solution": null, "status": null, "sampleTestCase": "{\"headers\": {\"Scores\": [\"Id\", \"Score\"]}, \"rows\": {\"Scores\": [[1, 3.50], [2, 3.65], [3, 4.00], [4, 3.85], [5, 4.00], [6, 3.65]]}}", "metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Scores (id int, score DECIMAL(3,2))\"\n ],\n \"mssql\": [\n \"Create table Scores (id int, score DECIMAL(3,2))\"\n ],\n \"oraclesql\": [\n \"Create table Scores (id int, score DECIMAL(3,2))\"\n ],\n \"database\": true\n}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [ "Create table If Not Exists Scores (id int, score DECIMAL(3,2))", "Truncate table Scores", "insert into Scores (id, score) values ('1', '3.5')", "insert into Scores (id, score) values ('2', '3.65')", "insert into Scores (id, score) values ('3', '4.0')", "insert into Scores (id, score) values ('4', '3.85')", "insert into Scores (id, score) values ('5', '4.0')", "insert into Scores (id, score) values ('6', '3.65')" ], "enableRunCode": true, "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"]}", "book": null, "isSubscribed": false, "isDailyQuestion": false, "dailyRecordStatus": null, "editorType": "CKEDITOR", "ugcQuestionId": null, "style": "LEETCODE", "exampleTestcases": "{\"headers\": {\"Scores\": [\"id\", \"score\"]}, \"rows\": {\"Scores\": [[1, 3.50], [2, 3.65], [3, 4.00], [4, 3.85], [5, 4.00], [6, 3.65]]}}", "__typename": "QuestionNode" } } }