查找空座位问题


空座位:

一个餐厅1000个座位,用1000行,一行一个整数、一个字符(描述位置的地址)来存储数据。要求管理这个餐厅的座位,方便查找出空座位。并且按照起始和结束座位号分为几个片区。即空座位号的起始和结束分为多少个空座位片区。 解惑1:在座位号加上正负号,正号代表空座位,负号代表已经入座。 update id=-id where id= @id 要根据座位号查找出输入哪个片区时候,可以用绝对值差select ABS(id) from seat 。结束营业时候,重置座位号set id=ABS(id) 。 该方法虽然简单,但是在一列中存在了2个属性, 解惑2: 再建立一个表,存放已入坐的,已入坐的在源表中删除对应表。 解惑3: 加入两列无用的行id为0和1001,座位标记界限。 createtableseat(idintnotnullprimarykey,areachar(1)) insertintoseatvalues(100,'A') SELECT*FROMseat 查找一片空座位中的最后一个空座位, selectidfromseatwhere(id+1)notin(selectidfromseat)andid<1001 找到一片空座位中的第一个位置: selectidfromseatwhere(id-1)notin(selectidfromseat)andid>0 现在使用两个视图把 createviewfirst_seat(id)asselectidfromseatwhere(id-1)notin(selectidfromseat)andid>0 createviewlast_seat(id)asselectidfromseatwhere(id+1)notin(selectidfromseat)andid<1001 找出空座位片区: selectf1.idasstart,l1.idasfinishfromfirst_seatasf1,last_seatl1wherel1.id=(selectmin(l2.id)fromlast_seatl2wheref1.id<=l2.id)

优质内容筛选与推荐>>
1、React学习之坑(一)-环境搭建
2、Ueditor在MVC中上传文件和远程图片下载的脚本
3、示例C#利用UdpClient发送广播消息<转>
4、Flex 布局语法教程
5、springMVC前后台数据交互


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号