{ "data": { "question": { "questionId": "178", "questionFrontendId": "178", "boundTopicId": null, "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 (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
\n\n

 

\n\n

Write a solution to find the rank of 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 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": null, "translatedContent": null, "isPaidOnly": false, "difficulty": "Medium", "likes": 2068, "dislikes": 267, "isLiked": null, "similarQuestions": "[]", "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]]}}", "categoryTitle": "Database", "contributors": [], "topicTags": [ { "name": "Database", "slug": "database", "translatedName": null, "__typename": "TopicTagNode" } ], "companyTagStats": null, "codeSnippets": [ { "lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below\n", "__typename": "CodeSnippetNode" }, { "lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */\n", "__typename": "CodeSnippetNode" }, { "lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */\n", "__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\n", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"353.1K\", \"totalSubmission\": \"575.2K\", \"totalAcceptedRaw\": 353149, \"totalSubmissionRaw\": 575242, \"acRate\": \"61.4%\"}", "hints": [], "solution": { "id": "1580", "canSeeDetail": false, "paidOnly": true, "hasVideoSolution": false, "paidOnlyVideo": true, "__typename": "ArticleNode" }, "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, "enableTestMode": false, "enableDebugger": false, "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", "libraryUrl": null, "adminUrl": null, "challengeQuestion": null, "__typename": "QuestionNode" } } }