LeetCode: 176. Second Highest Salary
LeetCode: 176. Second Highest Salary
タイトルの説明
Write a SQL query to get the second highest salary from the
For example, given the above
問題を解く構想.
まず、最高賃金を見つけて、最高賃金表と給与表を接続します.新しい表の
ACコード
タイトルの説明
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 |
+---------------------+
問題を解く構想.
まず、最高賃金を見つけて、最高賃金表と給与表を接続します.新しい表の
Salary < SecondHighestSalary
の最大値は、求めた2番目の高い給料です.ACコード
# Write your MySQL query statement below
select
MAX(Salary) as SecondHighestSalary
from
(select MAX(Salary) as HighestSalary from Employee) as HS, --
Employee as E
where HS.HighestSalary > E.Salary;