You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| 175 |[Form a Chemical Bond](https://leetcode.com/problems/form-a-chemical-bond/description/)|[Solution](solutions/175_form_a_chemical_bond.md)| LeetCode | Easy |`CROSS JOIN`|
212
212
| 176 |[Concatenate the Name and the Profession](https://leetcode.com/problems/concatenate-the-name-and-the-profession/description/)|[Solution](solutions/176_concatenate_the_name_and_the_profession.md)| LeetCode | Easy |`SUBSTRING` vs `LEFT`|
213
+
| 177 |[Consecutive Available Seats](https://leetcode.com/problems/consecutive-available-seats/description/)|[Solution](solutions/177_consecutive_available_seats.md)| LeetCode | Easy ||
213
214
<!-- Index End - WARNING: Do not delete or modify this markdown comment. -->
Find all the consecutive available seats in the cinema.
11
+
12
+
Return the result table **ordered** by `seat_id`**in ascending order**. [[Full Description](https://leetcode.com/problems/consecutive-available-seats/description/)]
13
+
14
+
## Submitted Solution
15
+
16
+
```sql
17
+
-- Submitted Solution
18
+
WITH cte1 AS (
19
+
SELECT
20
+
seat_id
21
+
,free
22
+
,LEAD(free) OVER (ORDER BY seat_id ASC) AS leadcol
23
+
,LAG(free) OVER (ORDER BY seat_id ASC) AS lagcol
24
+
FROM Cinema
25
+
),
26
+
cte2 AS (
27
+
SELECT
28
+
*
29
+
,CASE WHEN free =1AND leadcol =1AND lagcol IS NULL THEN seat_id
30
+
WHEN free =1AND leadcol =1AND lagcol =0 THEN seat_id
31
+
WHEN free =1AND leadcol =1AND lagcol =1 THEN seat_id
32
+
WHEN free =1AND leadcol IS NULLAND lagcol =1 THEN seat_id
33
+
WHEN free =1AND leadcol =0AND lagcol =1 THEN seat_id
0 commit comments