-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path176.second-highest-salary.sql
More file actions
50 lines (48 loc) · 1.14 KB
/
176.second-highest-salary.sql
File metadata and controls
50 lines (48 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
--
-- @lc app=leetcode id=176 lang=mysql
--
-- [176] Second Highest Salary
--
-- https://leetcode.com/problems/second-highest-salary/description/
--
-- database
-- Easy (31.14%)
-- Likes: 804
-- Dislikes: 437
-- Total Accepted: 237.4K
-- Total Submissions: 750.8K
-- Testcase Example: '{"headers": {"Employee": ["Id", "Salary"]}, "rows": {"Employee": [[1, 100], [2, 200], [3, 300]]}}'
--
-- 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 |
-- +---------------------+
--
--
--
-- @lc code=start
-- Write your MySQL query statement below
SELECT IFNULL((SELECT DISTINCT Salary
FROM Employee
order by Salary DESC LIMIT 1 OFFSET
1), NULL) AS SecondHighestSalary
-- @lc code=end