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 is an auto increment int, and free is bool ('1' means free, and '0' means occupied.).
Consecutive available seats are more than 2(inclusive) seats consecutively available.

因为只有一张表,所以需要join才能拿到更多信息

通过abs(a.seat_id - b.seat_id) = 1 找到相邻的座位

通过a.free = true and b.free = true 检查是否符合要求

最后通过distinct 和 order by 顺序输出

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

解题报告-603. Consecutive Available Seats的更多相关文章

  1. 【LeetCode】659. Split Array into Consecutive Subsequences 解题报告(Python)

    [LeetCode]659. Split Array into Consecutive Subsequences 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id ...

  2. LeetCode 解题报告索引

    最近在准备找工作的算法题,刷刷LeetCode,以下是我的解题报告索引,每一题几乎都有详细的说明,供各位码农参考.根据我自己做的进度持续更新中......                        ...

  3. ACM: Just a Hook 解题报告 -线段树

    E - Just a Hook Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   D ...

  4. 【LeetCode】481. Magical String 解题报告(Python)

    [LeetCode]481. Magical String 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http:/ ...

  5. 【LeetCode】331. Verify Preorder Serialization of a Binary Tree 解题报告(Python)

    [LeetCode]331. Verify Preorder Serialization of a Binary Tree 解题报告(Python) 标签: LeetCode 题目地址:https:/ ...

  6. 【LeetCode】468. Validate IP Address 解题报告(Python)

    [LeetCode]468. Validate IP Address 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: h ...

  7. CH Round #56 - 国庆节欢乐赛解题报告

    最近CH上的比赛很多,在此会全部写出解题报告,与大家交流一下解题方法与技巧. T1 魔幻森林 描述 Cortana来到了一片魔幻森林,这片森林可以被视作一个N*M的矩阵,矩阵中的每个位置上都长着一棵树 ...

  8. 二模13day1解题报告

    二模13day1解题报告 T1.发射站(station) N个发射站,每个发射站有高度hi,发射信号强度vi,每个发射站的信号只会被左和右第一个比他高的收到.现在求收到信号最强的发射站. 我用了时间复 ...

  9. BZOJ 1051 最受欢迎的牛 解题报告

    题目直接摆在这里! 1051: [HAOI2006]受欢迎的牛 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4438  Solved: 2353[S ...

随机推荐

  1. linux find查找并拷贝 exec xargs区别

    -exec    1.参数是一个一个传递的,传递一个参数执行一次rm    2.文件名有空格等特殊字符也能处理-xargs     1.一次将参数传给命令,可以使用-n控制参数个数    2.处理特殊 ...

  2. Qt UI界面改了,但UI界面不更新

    /**************************************************************************** * Qt UI界面改了,但UI界面不更新 * ...

  3. java并发回答

    java 线程安全比较重要的点:   在 java 编程中,记住这些关键点可以帮你避免一些严重的并发问题,比如条件竞争或死锁.   1).不可变对象默认是线程安全的,因为他们一旦被创建就不会被修改.比 ...

  4. thinkpad t420安装debian需要注意的细节

    关闭双显卡,使用集成显卡,32位可以用独显跑起来,但是64位的wheezy只能兼容集成显卡,不知道为啥,否则会在某些usb插入/或者拔出来以后,重启提示 failed to execute /lib/ ...

  5. 黄聪:“不允许对64位应用程序进行修改”的解决方法 --“Changes to 64-bit applications are not allowed.”

    在64位系统中使用VS对程序(32位的)进行调试,出现“不允许对64位应用程序进行修改”的提示,如下图所示: 解决方法:在VS主菜单上选择“生成” or "Build"——“配置管 ...

  6. WebService返回json格式数据供苹果或者安卓程序调用

    1.新建一个WebService. 2. /// <summary> /// DemoToJson 的摘要说明 /// </summary> [WebService(Names ...

  7. (转)TreeSet简单介绍与使用方法

    TreeSet简介 TreeSet是JAVA中集合的一种,TreeSet 是一个有序的集合,它的作用是提供有序的Set集合.它继承于AbstractSet抽象类,实现了NavigableSet< ...

  8. 一些部署django用到的linux命令

    mv untitled45/ /1601F/wang/ 将XXXX移动到XXX,也可以用于给XXX重新命名 zip -r -q -o hello.zip  /1601F/3/untitled45 安静 ...

  9. [转]iis 重新安装后 重新注册asp.net

    iis 重新安装后 重新注册asp.net 服务器IIS问题: 卸载并重新安装了IIS.... 解决方法:原因是IIS重装后要重新安装一下.NET Framework. 开始-->运行--> ...

  10. mysql-9索引

    mysql索引的建立对于mysql的高效运行是很重要的,索引可以大大提高mysql的检索速度. 索引分为单列索引和组合索引. 单列索引,即一个索引只包含单个列,一个表可以有多个单列索引,但这不是组合索 ...