{ "data": { "question": { "questionId": "177", "questionFrontendId": "177", "categoryTitle": "Database", "boundTopicId": 1091, "title": "Nth Highest Salary", "titleSlug": "nth-highest-salary", "content": "
Table: Employee
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| id | int |\n| salary | int |\n+-------------+------+\nid is the primary key column for this table.\nEach row of this table contains information about the salary of an employee.\n\n\n
\n\n
Write an SQL query to report the nth
highest salary from the Employee
table. If there is no nth
highest salary, the query should report null
.
The query result format is in the following example.
\n\n\n
Example 1:
\n\n\nInput: \nEmployee table:\n+----+--------+\n| id | salary |\n+----+--------+\n| 1 | 100 |\n| 2 | 200 |\n| 3 | 300 |\n+----+--------+\nn = 2\nOutput: \n+------------------------+\n| getNthHighestSalary(2) |\n+------------------------+\n| 200 |\n+------------------------+\n\n\n
Example 2:
\n\n\nInput: \nEmployee table:\n+----+--------+\n| id | salary |\n+----+--------+\n| 1 | 100 |\n+----+--------+\nn = 2\nOutput: \n+------------------------+\n| getNthHighestSalary(2) |\n+------------------------+\n| null |\n+------------------------+\n\n", "translatedTitle": "第N高的薪水", "translatedContent": "
表: Employee
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| id | int |\n| salary | int |\n+-------------+------+\nId是该表的主键列。\n该表的每一行都包含有关员工工资的信息。\n\n\n
\n\n
编写一个SQL查询来报告 Employee
表中第 n
高的工资。如果没有第 n
个最高工资,查询应该报告为 null
。
查询结果格式如下所示。
\n\n\n\n
示例 1:
\n\n\n输入: \nEmployee table:\n+----+--------+\n| id | salary |\n+----+--------+\n| 1 | 100 |\n| 2 | 200 |\n| 3 | 300 |\n+----+--------+\nn = 2\n输出: \n+------------------------+\n| getNthHighestSalary(2) |\n+------------------------+\n| 200 |\n+------------------------+\n\n\n
示例 2:
\n\n\n输入: \nEmployee 表:\n+----+--------+\n| id | salary |\n+----+--------+\n| 1 | 100 |\n+----+--------+\nn = 2\n输出: \n+------------------------+\n| getNthHighestSalary(2) |\n+------------------------+\n| null |\n+------------------------+\n", "isPaidOnly": false, "difficulty": "Medium", "likes": 586, "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": "CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT\nBEGIN\n RETURN (\n # Write your MySQL query statement below.\n \n );\nEND", "__typename": "CodeSnippetNode" }, { "lang": "MS SQL Server", "langSlug": "mssql", "code": "CREATE FUNCTION getNthHighestSalary(@N INT) RETURNS INT AS\nBEGIN\n RETURN (\n /* Write your T-SQL query statement below. */\n \n );\nEND", "__typename": "CodeSnippetNode" }, { "lang": "Oracle", "langSlug": "oraclesql", "code": "CREATE FUNCTION getNthHighestSalary(N IN NUMBER) RETURN NUMBER IS\nresult NUMBER;\nBEGIN\n /* Write your PL/SQL query statement below */\n \n RETURN result;\nEND;", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"157.6K\", \"totalSubmission\": \"339.3K\", \"totalAcceptedRaw\": 157551, \"totalSubmissionRaw\": 339264, \"acRate\": \"46.4%\"}", "hints": [], "solution": null, "status": null, "sampleTestCase": "{\"headers\": {\"Employee\": [\"Id\", \"Salary\"]}, \"argument\": 2, \"rows\": {\"Employee\": [[1, 100], [2, 200], [3, 300]]}}", "metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Employee (Id int, Salary int)\"\n ],\n \"mssql\": [\n \"Create table Employee (Id int, Salary int)\"\n ],\n \"oraclesql\": [\n \"Create table Employee (Id int, Salary int)\"\n ],\n \"database\": true,\n \"manual\": true\n}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [ "Create table If Not Exists Employee (Id int, Salary int)", "Truncate table Employee", "insert into Employee (id, salary) values ('1', '100')", "insert into Employee (id, salary) values ('2', '200')", "insert into Employee (id, salary) values ('3', '300')" ], "enableRunCode": true, "envInfo": "{\"mysql\":[\"MySQL\",\"
\\u7248\\u672c\\uff1a 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\": {\"Employee\": [\"id\", \"salary\"]}, \"argument\": 2, \"rows\": {\"Employee\": [[1, 100], [2, 200], [3, 300]]}}\n{\"headers\": {\"Employee\": [\"id\", \"salary\"]}, \"argument\": 2, \"rows\": {\"Employee\": [[1, 100]]}}",
"__typename": "QuestionNode"
}
}
}MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"