如何在SQL Server 2008中加入2个表 [英] HOW TO JOIN 2 tables in SQL Server 2008

查看:78
本文介绍了如何在SQL Server 2008中加入2个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个表dbo.seatdbo.booking

dbo.seat

noSeat
------
1-2
1-3
1-4
1-8
4-2
4-3
4-4
5-1
5-2

dbo.booking

noBooking   |  noSeat  | statusBooked |       endTime
1002           1-4            0         2015-02-16 13:30:00.000
1003           1-4            1         2015-02-17 13:30:00.000
1004           1-8            1         2015-02-17 13:30:00.000
1005           1-2            0         2015-02-16 14:59:00.000
1006           1-3            0         2015-02-16 14:59:00.000

如何获取未预订的seat.noSeat?

此示例向我们表明seat 1-4和1-8号已预订.我想知道可用的座位(输出是除了1-4和1-8以外的所有seat.noSeat)?

This sample show us that seat number 1-4 and 1-8 is booked. and I want to know what seat is available(the output is all seat.noSeat except 1-4 and 1-8) ?

booking用于预订交易,seat是提供的座位列表.

Table booking is for booking transaction and seat is list of seat provided.

更新:

statusBooked将自动更新为0.这意味着结束了,并告诉我们1-4可用,直到有人再次预订为止(默认情况下将方法插入dbo.booking statusBooked 1)

statusBooked will automatically update to 0 when endTime is equal CurrentTime. it mean it's over and tell us that 1-4 is available until someone booked it again (insert method to dbo.booking statusBooked by default 1)

推荐答案

select *
from dbo.seat
where noseat not in (
    select noseat
    from dbo.booking
    where statusbooking = 1
)

这是我的猜测.我不能说我真的了解座位"的含义(除非它是座位数")?

Here's my guess. I can't say I really understand what "noseat" means (unless it's "number of seat")?

这篇关于如何在SQL Server 2008中加入2个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆