0
点赞
收藏
分享

微信扫一扫

LeetCode(数据库)- 连续空余座位


题目链接:​​点击打开链接​​


题目大意:略。


解题思路:略。


AC 代码

-- 解题方案(1)
select distinct a.seat_id
from cinema a join cinema b
on abs(a.seat_id - b.seat_id) = 1
and a.free = true and b.free = true
order by a.seat_id;

-- 解题方案(2)
WITH t1 AS(SELECT c1.seat_id id1, c2.seat_id id2
FROM cinema c1
INNER JOIN cinema c2 ON c1.seat_id + 1 = c2.seat_id AND c1.free = 1 AND c2.free = 1)

SELECT *
FROM (SELECT id1 seat_id FROM t1
UNION
SELECT id2 FROM t1) t
ORDER BY seat_id


举报

相关推荐

leetcode数据库中等题目

0 条评论