mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
93 lines
8.0 KiB
JSON
93 lines
8.0 KiB
JSON
{
|
||
"data": {
|
||
"question": {
|
||
"questionId": "178",
|
||
"questionFrontendId": "178",
|
||
"categoryTitle": "Database",
|
||
"boundTopicId": 1125,
|
||
"title": "Rank Scores",
|
||
"titleSlug": "rank-scores",
|
||
"content": "<p>Table: <code>Scores</code></p>\n\n<pre>\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| id | int |\n| score | decimal |\n+-------------+---------+\nid is the primary key (column with unique values) 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</pre>\n\n<p> </p>\n\n<p>Write a solution to find the rank of the scores. The ranking should be calculated according to the following rules:</p>\n\n<ul>\n\t<li>The scores should be ranked from the highest to the lowest.</li>\n\t<li>If there is a tie between two scores, both should have the same ranking.</li>\n\t<li>After a tie, the next ranking number should be the next consecutive integer value. In other words, there should be no holes between ranks.</li>\n</ul>\n\n<p>Return the result table ordered by <code>score</code> in descending order.</p>\n\n<p>The result format is in the following example.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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+----+-------+\n<strong>Output:</strong> \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</pre>\n",
|
||
"translatedTitle": "分数排名",
|
||
"translatedContent": "<p>表: <code>Scores</code></p>\n\n<pre>\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| id | int |\n| score | decimal |\n+-------------+---------+\n在 SQL 中,id 是该表的主键。\n该表的每一行都包含了一场比赛的分数。Score 是一个有两位小数点的浮点值。\n</pre>\n\n<p> </p>\n\n<p>查询并对分数进行排序。排名按以下规则计算:</p>\n\n<ul>\n\t<li>分数应按从高到低排列。</li>\n\t<li>如果两个分数相等,那么两个分数的排名应该相同。</li>\n\t<li>在排名相同的分数后,排名数应该是下一个连续的整数。换句话说,排名之间不应该有空缺的数字。</li>\n</ul>\n\n<p>按 <code>score</code> 降序返回结果表。</p>\n\n<p>查询结果格式如下所示。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong> \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<strong>输出:</strong> \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+-------+------+</pre>\n",
|
||
"isPaidOnly": false,
|
||
"difficulty": "Medium",
|
||
"likes": 1152,
|
||
"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, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": 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"
|
||
},
|
||
{
|
||
"lang": "Pandas",
|
||
"langSlug": "pythondata",
|
||
"code": "import pandas as pd\n\ndef order_scores(scores: pd.DataFrame) -> pd.DataFrame:\n ",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "PostgreSQL",
|
||
"langSlug": "postgresql",
|
||
"code": "-- Write your PostgreSQL query statement below",
|
||
"__typename": "CodeSnippetNode"
|
||
}
|
||
],
|
||
"stats": "{\"totalAccepted\": \"221.8K\", \"totalSubmission\": \"360.5K\", \"totalAcceptedRaw\": 221811, \"totalSubmissionRaw\": 360489, \"acRate\": \"61.5%\"}",
|
||
"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": "{\"mysql\":[\"Create table If Not Exists Scores (id int, score DECIMAL(3,2))\"],\"mssql\":[\"Create table Scores (id int, score DECIMAL(3,2))\"],\"oraclesql\":[\"Create table Scores (id int, score DECIMAL(3,2))\"],\"database\":true,\"name\":\"order_scores\",\"pythondata\":[\"Scores = pd.DataFrame([], columns=['id', 'score']).astype({'id':'Int64', 'score':'Float64'})\"],\"manual\":false,\"postgresql\":[\"Create table If Not Exists Scores (id int, score DECIMAL(3,2))\"],\"database_schema\":{\"Scores\":{\"id\":\"INT\",\"score\":\"DECIMAL(3, 2)\"}}}",
|
||
"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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>PostgreSQL 16<\\/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"
|
||
}
|
||
}
|
||
} |