当前位置: 首页> 文旅> 酒店 > 找个人制作网页的网站_90设计网站几次是什么意思_守游网络推广平台_企业网站制作公司

找个人制作网页的网站_90设计网站几次是什么意思_守游网络推广平台_企业网站制作公司

时间:2025/7/10 12:31:39来源:https://blog.csdn.net/m0_70882914/article/details/142626047 浏览次数:0次
找个人制作网页的网站_90设计网站几次是什么意思_守游网络推广平台_企业网站制作公司

文章目录

  • 1. 603.连续空余座位
    • 1.1 题干
    • 1.2 准备数据
    • 1.3 思路分析
    • 1.4 解法
    • 1.5 结果截图

1. 603.连续空余座位

1.1 题干

表: Cinema

±------------±-----+
| Column Name | Type |
±------------±-----+
| seat_id | int |
| free | bool |
±------------±-----+
Seat_id 是该表的自动递增主键列。
在 PostgreSQL 中,free 存储为整数。请使用 ::boolean 将其转换为布尔格式。
该表的每一行表示第 i 个座位是否空闲。1 表示空闲,0 表示被占用。

查找电影院所有连续可用的座位。

返回按 seat_id 升序排序 的结果表。

测试用例的生成使得两个以上的座位连续可用。

结果表格式如下所示。

示例 1:

输入:
Cinema 表:
±--------±-----+
| seat_id | free |
±--------±-----+
| 1 | 1 |
| 2 | 0 |
| 3 | 1 |
| 4 | 1 |
| 5 | 1 |
±--------±-----+
输出:
±--------+
| seat_id |
±--------+
| 3 |
| 4 |
| 5 |
±--------+

1.2 准备数据

Create table If Not Exists Cinema (seat_id int primary key auto_increment, free bool)
Truncate table Cinema
insert into Cinema (seat_id, free) values ('1', '1')
insert into Cinema (seat_id, free) values ('2', '0')
insert into Cinema (seat_id, free) values ('3', '1')
insert into Cinema (seat_id, free) values ('4', '1')
insert into Cinema (seat_id, free) values ('5', '1')

1.3 思路分析

在这里插入图片描述

1.4 解法

select distinct c2.seat_id from Cinema c1,Cinema c2 where abs(c1.seat_id-c2.seat_id)=1 and c1.free=1 and c2.free=1;

1.5 结果截图

在这里插入图片描述

关键字:找个人制作网页的网站_90设计网站几次是什么意思_守游网络推广平台_企业网站制作公司

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: