1、176题目,Second Highest Salary,https://leetcode.com/problems/second-highest-salary/#/description

  Write a SQL query to get the second highest salary from the Employee table.

+----+--------+
| Id | Salary |
+----+--------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
+----+--------+

  For example, given the above Employee table, the query should return 200 as the second highest salary. If there is no second highest salary, then the query should return null.

+---------------------+
| SecondHighestSalary |
+---------------------+
| 200 |
+---------------------+
select (
select distinct Salary from Employee order by Salary Desc limit 1 offset 1
)as second;
————————————————————————————————————————
177. Nth Highest Salary

Write a SQL query to get the nth highest salary from the Employee table.

+----+--------+
| Id | Salary |
+----+--------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
+----+--------+

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.

+------------------------+
| getNthHighestSalary(2) |
+------------------------+
| 200 |
+------------------------+

CREATE FUNCTION getNthHighestSalary(N INT)

RETURNS INT

BEGIN

DECLARE M INT;

SET M=N-1;

  RETURN (

    SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT M, 1]

);

END

最新文章

  1. JavaScript的妙与乐(一)之 函数优化
  2. Codeforces 500B. New Year Permutation[连通性]
  3. BZOJ1997 [Hnoi2010]Planar (2-sat)
  4. 微信 token 验证
  5. xcode6 iOS sdk8.1隐藏系统状态栏
  6. mysql_view
  7. Java中使用CountDownLatch进行多线程同步
  8. Python-bootstrap
  9. 彻底理解mysql服务器的字符集转换问题
  10. 高级定时器TIM1&TIM8
  11. pre打印
  12. E_FAIL (0x80004005) MachineWrap
  13. A - Class Statistics
  14. Java中的单利模式介绍
  15. UI5-文档-4.28-Unit Test with QUnit
  16. (1/24) 认识webpack
  17. [Jenkins] 全局变量
  18. Uncaught TypeError: Cannot read property 'addEventListener'
  19. 转帖:kindeditor编辑区空格被隐藏,导致所见所得不一致的解决办法
  20. HDFS相关概念

热门文章

  1. bootstrap插件实用方法
  2. api响应类
  3. uart测试代码
  4. 主攻ASP.NET MVC4.0之重生:CheckBoxListHelper和RadioBoxListHelper的使用
  5. jQuery仿苹果样式焦点图插件
  6. Swift_初识Swift
  7. DATE_FORMAT() 函数用于以不同的格式显示日期/时间数据。
  8. 【bzoj1876】[SDOI2009]SuperGCD(高精度)
  9. 考勤助手ER图2.0版本所存在的问题
  10. QT 使用QPainter 绘制图形 和 世界变换 world transform