Leetcode刷题122-176. 第二高的薪水(MySQL和Oracle解法!!!)

Come from : [https://leetcode-cn.com/problems/second-highest-salary/comments/]

176. Second Highest Salary

  • 1.Question
  • 2.Answer
  • 3.我的收获

1.Question

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

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

例如上述 Employee 表,SQL查询应该返回 200 作为第二高的薪水。如果不存在第二高的薪水,那么查询应返回 null。

+---------------------+
| SecondHighestSalary |
+---------------------+
| 200                 |
+---------------------+

2.Answer

easy 类型题目。简单的SQL语句查询(不多BB).

AC代码如下(Oracle和MySQL都能AC):

# Write your MySQL query statement below
select max(salary) SecondHighestSalary from Employee a
where a.salary < (select max(salary) from Employee)

3.我的收获

fighting。。。
注意总结 Oracle 和 MySQL的 语法区别~

2019/7/12 胡云层 于南京 122

你可能感兴趣的:(LeetCode从零开始)