leetcode_sql_1,176,177
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
最新文章
- JavaScript的妙与乐(一)之 函数优化
- Codeforces 500B. New Year Permutation[连通性]
- BZOJ1997 [Hnoi2010]Planar (2-sat)
- 微信 token 验证
- xcode6 iOS sdk8.1隐藏系统状态栏
- mysql_view
- Java中使用CountDownLatch进行多线程同步
- Python-bootstrap
- 彻底理解mysql服务器的字符集转换问题
- 高级定时器TIM1&;TIM8
- pre打印
- E_FAIL (0x80004005) MachineWrap
- A - Class Statistics
- Java中的单利模式介绍
- UI5-文档-4.28-Unit Test with QUnit
- (1/24) 认识webpack
- [Jenkins] 全局变量
- Uncaught TypeError: Cannot read property 'addEventListener'
- 转帖:kindeditor编辑区空格被隐藏,导致所见所得不一致的解决办法
- HDFS相关概念
热门文章
- bootstrap插件实用方法
- api响应类
- uart测试代码
- 主攻ASP.NET MVC4.0之重生:CheckBoxListHelper和RadioBoxListHelper的使用
- jQuery仿苹果样式焦点图插件
- Swift_初识Swift
- DATE_FORMAT() 函数用于以不同的格式显示日期/时间数据。
- 【bzoj1876】[SDOI2009]SuperGCD(高精度)
- 考勤助手ER图2.0版本所存在的问题
- QT 使用QPainter 绘制图形 和 世界变换 world transform