Skip to content

Commit 00e0466

Browse files
committed
Upload 131
1 parent 6d852ee commit 00e0466

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ The problems and both submitted and site solutions are documented in individual
163163
| 128 | [Last Person to Fit in the Bus](https://leetcode.com/problems/last-person-to-fit-in-the-bus/description/) | [Solution](solutions/128_last_person_to_fit_in_the_bus.md) | LeetCode | Medium | `ORDER BY turn RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW` |
164164
| 129 | [Count Salary Categories](https://leetcode.com/problems/count-salary-categories/description/) | [Solution](solutions/129_count_salary_categories.md) | LeetCode | Medium | `IFNULL` |
165165
| 130 | [Employees Whose Manager Left the Company](https://leetcode.com/problems/employees-whose-manager-left-the-company/description/) | [Solution](solutions/130_employees_whose_manager_left_the_company.md) | LeetCode | Easy | |
166+
| 131 | [Exchange Seats](https://leetcode.com/problems/exchange-seats/description/) | [Solution](solutions/131_exchange_seats.md) | LeetCode | Medium | `CASE` w/ `LAG` w/ `COALESCE` |
166167
<!-- Index End - WARNING: Do not delete or modify this markdown comment. -->
167168

168169
## Author(s)

solutions/131_exchange_seats.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# SQL Everyday \#131
2+
3+
## Exchange Seats
4+
5+
Site: LeetCode\
6+
Difficulty per Site: Medium
7+
8+
## Problem
9+
10+
Write a solution to swap the seat id of every two consecutive students. If the number of students is odd, the id of the last student is not swapped.
11+
12+
Return the result table ordered by `id` in *ascending* order. [[Full Description](https://leetcode.com/problems/exchange-seats/description/)]
13+
14+
## Submitted Solution
15+
16+
```sql
17+
-- Submitted Solution
18+
SELECT
19+
id
20+
,CASE WHEN id % 2 = 0 THEN LAG(student) OVER (ORDER BY id)
21+
ELSE COALESCE(LEAD(student) OVER (ORDER BY id), student)
22+
END AS student
23+
FROM Seat
24+
;
25+
```
26+
27+
## Site Solution
28+
29+
```sql
30+
-- LeetCode Solution
31+
-- TBD
32+
```
33+
34+
## Notes
35+
36+
TBD
37+
38+
## NB
39+
40+
`CASE` w/ `LAG` w/ `COALESCE`
41+
42+
Go to [Table of Contents](/README.md#contents)\
43+
Go to [Overview](/README.md)

0 commit comments

Comments
 (0)