176. Second Highest Salary

Leetcode 問題: 176. Second Highest Salary

題目

找出 Employee 資料表第二高薪的薪水

  • 若沒有第二高薪水的話則回傳 null
  • 若第一高有兩個人,薪水一樣高,但沒其他人了,則第二高為 null

Employee 資料表

Id Salary
1 100
2 200
3 300
4 100
# Write your MySQL query statement below
SELECT(
  SELECT DISTINCT `Salary`
  FROM `Employee`
  ORDER BY `Salary` DESC
  LIMIT 1 OFFSET 1
) as `SecondHighestSalary`