LeetCode(数据库)- 连续空余座位
Posted Lux_Sun
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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(数据库)- 连续空余座位的主要内容,如果未能解决你的问题,请参考以下文章