1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-21 04:56:46 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/originData/nth-highest-salary.json
2025-09-29 14:43:44 +08:00

90 lines
8.6 KiB
JSON

{
"data": {
"question": {
"questionId": "177",
"questionFrontendId": "177",
"categoryTitle": "Database",
"boundTopicId": 1091,
"title": "Nth Highest Salary",
"titleSlug": "nth-highest-salary",
"content": "<p>Table: <code>Employee</code></p>\n\n<pre>\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| id | int |\n| salary | int |\n+-------------+------+\nid is the primary key (column with unique values) for this table.\nEach row of this table contains information about the salary of an employee.\n</pre>\n\n<p>&nbsp;</p>\n\n<p>Write a solution to find the <code>n<sup>th</sup></code> highest <strong>distinct</strong> salary from the <code>Employee</code> table. If there are less than <code>n</code> distinct salaries, return&nbsp;<code>null</code>.</p>\n\n<p>The result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nEmployee table:\n+----+--------+\n| id | salary |\n+----+--------+\n| 1 | 100 |\n| 2 | 200 |\n| 3 | 300 |\n+----+--------+\nn = 2\n<strong>Output:</strong> \n+------------------------+\n| getNthHighestSalary(2) |\n+------------------------+\n| 200 |\n+------------------------+\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nEmployee table:\n+----+--------+\n| id | salary |\n+----+--------+\n| 1 | 100 |\n+----+--------+\nn = 2\n<strong>Output:</strong> \n+------------------------+\n| getNthHighestSalary(2) |\n+------------------------+\n| null |\n+------------------------+\n</pre>\n",
"translatedTitle": "第N高的薪水",
"translatedContent": "<p>表:&nbsp;<code>Employee</code></p>\n\n<pre>\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| id | int |\n| salary | int |\n+-------------+------+\nid 是该表的主键(列中的值互不相同)。\n该表的每一行都包含有关员工工资的信息。\n</pre>\n\n<p>&nbsp;</p>\n\n<p>编写一个解决方案查询&nbsp;<code>Employee</code> 表中第 <code>n</code> 高的&nbsp;<strong>不同</strong> 工资。如果少于&nbsp;<code>n</code> 个不同工资,查询结果应该为&nbsp;<code>null</code> 。</p>\n\n<p>查询结果格式如下所示。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong> \nEmployee table:\n+----+--------+\n| id | salary |\n+----+--------+\n| 1 | 100 |\n| 2 | 200 |\n| 3 | 300 |\n+----+--------+\nn = 2\n<strong>输出:</strong> \n+------------------------+\n| getNthHighestSalary(2) |\n+------------------------+\n| 200 |\n+------------------------+\n</pre>\n\n<p><strong>示例 2:</strong></p>\n\n<pre>\n<strong>输入:</strong> \nEmployee 表:\n+----+--------+\n| id | salary |\n+----+--------+\n| 1 | 100 |\n+----+--------+\nn = 2\n<strong>输出:</strong> \n+------------------------+\n| getNthHighestSalary(2) |\n+------------------------+\n| null |\n+------------------------+</pre>\n",
"isPaidOnly": false,
"difficulty": "Medium",
"likes": 821,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[{\"title\": \"The Number of Users That Are Eligible for Discount\", \"titleSlug\": \"the-number-of-users-that-are-eligible-for-discount\", \"difficulty\": \"Easy\", \"translatedTitle\": \"\\u6709\\u8d44\\u683c\\u4eab\\u53d7\\u6298\\u6263\\u7684\\u7528\\u6237\\u6570\\u91cf\", \"isPaidOnly\": true}]",
"contributors": [],
"langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python3\": false, \"python\": false, \"javascript\": false, \"typescript\": false, \"csharp\": false, \"c\": false, \"golang\": false, \"kotlin\": false, \"swift\": false, \"rust\": false, \"ruby\": false, \"php\": false, \"dart\": false, \"scala\": false, \"elixir\": false, \"erlang\": false, \"racket\": false, \"cangjie\": false, \"bash\": false, \"html\": false, \"pythonml\": false, \"react\": false, \"vanillajs\": false, \"mysql\": false, \"mssql\": false, \"postgresql\": false, \"oraclesql\": false, \"pythondata\": 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": "PostgreSQL",
"langSlug": "postgresql",
"code": "CREATE OR REPLACE FUNCTION NthHighestSalary(N INT) RETURNS TABLE (Salary INT) AS $$\nBEGIN\n RETURN QUERY (\n -- Write your PostgreSQL query statement below.\n \n \n );\nEND;\n$$ LANGUAGE plpgsql;",
"__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"
},
{
"lang": "Pandas",
"langSlug": "pythondata",
"code": "import pandas as pd\n\ndef nth_highest_salary(employee: pd.DataFrame, N: int) -> pd.DataFrame:",
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"274.3K\", \"totalSubmission\": \"597.5K\", \"totalAcceptedRaw\": 274333, \"totalSubmissionRaw\": 597461, \"acRate\": \"45.9%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\": {\"Employee\": [\"id\", \"salary\"]}, \"argument\": 2, \"rows\": {\"Employee\": [[1, 100], [2, 200], [3, 300]]}}",
"metaData": "{\"mysql\":[\"Create table If Not Exists Employee (Id int, Salary int)\"],\"mssql\":[\"Create table Employee (Id int, Salary int)\"],\"oraclesql\":[\"Create table Employee (Id int, Salary int)\"],\"database\":true,\"manual\":true,\"name\":\"nth_highest_salary\",\"pythondata\":[\"Employee = pd.DataFrame([], columns=['Id', 'Salary']).astype({'Id':'Int64', 'Salary':'Int64'})\"],\"database_schema\":{\"Employee\":{\"Id\":\"INT\",\"Salary\":\"INT\"}}}",
"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\",\"<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.2.2 and NumPy 1.26.4<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>PostgreSQL 16<\\/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"
}
}
}