Nav: << previous: 176.第二高的薪水 | next: 178.分数排名 >>
Description
tab: English
<p>Table: <code>Employee</code></p>
<pre>
+-------------+------+
| Column Name | Type |
+-------------+------+
| id | int |
| salary | int |
+-------------+------+
id is the primary key (column with unique values) for this table.
Each row of this table contains information about the salary of an employee.
</pre>
<p> </p>
<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 <code>null</code>.</p>
<p>The result format is in the following example.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong>
Employee table:
+----+--------+
| id | salary |
+----+--------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
+----+--------+
n = 2
<strong>Output:</strong>
+------------------------+
| getNthHighestSalary(2) |
+------------------------+
| 200 |
+------------------------+
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong>
Employee table:
+----+--------+
| id | salary |
+----+--------+
| 1 | 100 |
+----+--------+
n = 2
<strong>Output:</strong>
+------------------------+
| getNthHighestSalary(2) |
+------------------------+
| null |
+------------------------+
</pre>
---
[submissions](https://leetcode.com/problems/nth-highest-salary/submissions/) | [solutions](https://leetcode.com/problems/nth-highest-salary/solutions/)
tab: 中文
<p>表: <code>Employee</code></p>
<pre>
+-------------+------+
| Column Name | Type |
+-------------+------+
| id | int |
| salary | int |
+-------------+------+
id 是该表的主键(列中的值互不相同)。
该表的每一行都包含有关员工工资的信息。
</pre>
<p> </p>
<p>编写一个解决方案查询 <code>Employee</code> 表中第 <code>n</code> 高的 <strong>不同</strong> 工资。如果少于 <code>n</code> 个不同工资,查询结果应该为 <code>null</code> 。</p>
<p>查询结果格式如下所示。</p>
<p> </p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong>
Employee table:
+----+--------+
| id | salary |
+----+--------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
+----+--------+
n = 2
<strong>输出:</strong>
+------------------------+
| getNthHighestSalary(2) |
+------------------------+
| 200 |
+------------------------+
</pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong>
Employee 表:
+----+--------+
| id | salary |
+----+--------+
| 1 | 100 |
+----+--------+
n = 2
<strong>输出:</strong>
+------------------------+
| getNthHighestSalary(2) |
+------------------------+
| null |
+------------------------+</pre>
---
[提交记录](https://leetcode.cn/problems/nth-highest-salary/submissions/) | [题解](https://leetcode.cn/problems/nth-highest-salary/solution/)
Solutions & Notes
properties:
note.updated:
displayName: Last Updated
note.relative_links:
displayName: Related Links
note.desc:
displayName: Description
note.grade:
displayName: Rating
note.program_language:
displayName: Language
note.time_complexity:
displayName: TC
note.space_complexity:
displayName: SC
views:
- type: table
name: Solutions & Notes
filters:
and:
- file.hasLink(this.file)
- file.tags.containsAny("leetcode/solution", "leetcode/note")
order:
- file.name
- desc
- program_language
- time_complexity
- space_complexity
- grade
- relative_links
- updated
sort:
- property: grade
direction: ASC
- property: time_complexity
direction: ASC
- property: program_language
direction: ASC
columnSize:
file.name: 104
note.space_complexity: 65
note.grade: 126
Similar Problems
properties:
note.lcTopics:
displayName: Topics
note.lcAcRate:
displayName: AC Rate
note.favorites:
displayName: Favorites
note.grade:
displayName: Rating
note.translatedTitle:
displayName: Title (CN)
note.lcDifficulty:
displayName: Difficulty
views:
- type: table
name: Similar Problems
filters:
and:
- file.hasLink(this.file)
- similarQuestions.contains(this.file)
order:
- file.name
- translatedTitle
- lcTopics
- lcDifficulty
- lcAcRate
- grade
- favorites
sort:
- property: file.name
direction: ASC
- property: lcTopics
direction: DESC
columnSize:
note.translatedTitle: 240
note.lcTopics: 347
note.lcAcRate: 75
note.grade: 122