Skip to content

Commit 7d8d173

Browse files
committed
Upload 139
1 parent e23598f commit 7d8d173

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ The problems and both submitted and site solutions are documented in individual
171171
| 136 | [Department Top Three Salaries](https://leetcode.com/problems/department-top-three-salaries/description/) | [Solution](solutions/136_department_top_three_salaries.md) | LeetCode | Hard | |
172172
| 137 | [Fix Names in a Table](https://leetcode.com/problems/fix-names-in-a-table/description/) | [Solution](solutions/137_fix_names_in_a_table.md) | LeetCode | Easy | `SUBSTRING()` |
173173
| 138 | [Patients With a Condition](https://leetcode.com/problems/patients-with-a-condition/description/) | [Solution](solutions/138_patients_with_a_condition.md) | LeetCode | Easy | |
174+
| 139 | [Second Highest Salary](https://leetcode.com/problems/second-highest-salary/description/) | [Solution](solutions/139_second_highest_salary.md) | LeetCode | Medium | |
174175
<!-- Index End - WARNING: Do not delete or modify this markdown comment. -->
175176

176177
## Author(s)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# SQL Everyday \#139
2+
3+
## Second Highest Salary
4+
5+
Site: LeetCode\
6+
Difficulty per Site: Medium
7+
8+
## Problem
9+
10+
Write a solution to find the second highest *distinct* salary from the `Employee` table. If there is no second highest salary, return `null (return None in Pandas)`. [[Full Description](https://leetcode.com/problems/second-highest-salary/description/)]
11+
12+
## Submitted Solution
13+
14+
```sql
15+
-- Submitted Solution
16+
WITH cte1 AS (
17+
SELECT
18+
DISTINCT salary
19+
FROM Employee
20+
),
21+
cte2 AS (
22+
SELECT
23+
salary
24+
,ROW_NUMBER() OVER (ORDER BY salary DESC) AS row_num
25+
,COUNT(*) OVER () AS row_count
26+
FROM cte1
27+
)
28+
SELECT
29+
CASE WHEN row_count >= 2 THEN (SELECT salary FROM cte2 WHERE row_num = 2) ELSE null END AS SecondHighestSalary
30+
FROM cte2
31+
LIMIT 1
32+
;
33+
```
34+
35+
## Site Solution
36+
37+
```sql
38+
-- LeetCode Solution
39+
-- TBD
40+
```
41+
42+
## Notes
43+
44+
TBD
45+
46+
## NB
47+
48+
49+
50+
Go to [Index](../?tab=readme-ov-file#index)\
51+
Go to [Overview](../?tab=readme-ov-file)
52+

0 commit comments

Comments
 (0)