美文网首页
【leetcode】177. 第N高的薪水-中等

【leetcode】177. 第N高的薪水-中等

作者: 流年残雪 | 来源:发表于2020-12-01 14:20 被阅读0次

【题目】

编写一个 SQL 查询,获取 Employee 表中第 n 高的薪水(Salary)。

Id Salary
1 100
2 200
3 300

例如上述 Employee 表,n = 2 时,应返回第二高的薪水 200。如果不存在第 n 高的薪水,那么查询应返回 null

getNthHighestSalary(2)
200

【题解】

select distinct salary 
from
      (select dense_rank() over(order by salary desc)  as rk,salary
       from employee) a
       where a.rk=n;

相关文章

网友评论

      本文标题:【leetcode】177. 第N高的薪水-中等

      本文链接:https://www.haomeiwen.com/subject/ealswktx.html