题目
Several friends at a cinema ticket office would like to reserve consecutive available seats.
Can you help to query all the consecutive available seats order by the seat_id using the following cinema table?
| seat_id | free |
|---|---|
| 1 | 1 |
| 2 | 0 |
| 3 | 1 |
| 4 | 1 |
| 5 | 1 |
Your query should return the following result for the sample case above.
| seat_id |
|---|
| 3 |
| 4 |
| 5 |
Note:
The seat_id

在一家电影院的售票处,朋友们希望预订连续的空座。利用cinema表,你需要编写SQL查询按seat_id升序返回所有连续的空座。注意:seat_id是自增整数,free字段表示座位状态(1为空,0为已占)。连续的空座至少包括3个。此题解将展示如何结合LEAD和LAG函数来解决这个问题。
1万+

被折叠的 条评论
为什么被折叠?



