Problem
Write a SQL query to get the nth highest salary from the Employee table.
|
|
For example, given the above Employee table, the nth highest salary where n = 2 is 200. If there is no nth highest salary, then the query should return null.
|
|
Analysis
We can solve this problem with LIMIT and OFFSET. We can sort by salary in descending order first, then skip n-1 numbers and output the first number.
Solution
|
|
Link
177. Nth Highest Salary
(中文版) SQL 笔记: Leetcode#177 Nth Highest Salary
近期评论