如何加入 SQL Server 2008 中的 2 个表
HOW TO JOIN 2 tables in SQL Server 2008
我有 2 个表 dbo.seat
和 dbo.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)?
Table booking
为预订交易,seat
为提供的座位列表。
更新:
statusBooked
当 endTime 等于 CurrentTime
时会自动更新为 0。这意味着它已经结束并告诉我们 1-4 可用,直到有人再次预订它(将方法插入 dbo.booking
statusBooked
默认情况下 1)
select *
from dbo.seat
where noseat not in (
select noseat
from dbo.booking
where statusbooking = 1
)
这是我的猜测。我不能说我真的明白 "noseat" 是什么意思(除非是 "number of seat")?
我有 2 个表 dbo.seat
和 dbo.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)?
Table booking
为预订交易,seat
为提供的座位列表。
更新:
statusBooked
当 endTime 等于 CurrentTime
时会自动更新为 0。这意味着它已经结束并告诉我们 1-4 可用,直到有人再次预订它(将方法插入 dbo.booking
statusBooked
默认情况下 1)
select *
from dbo.seat
where noseat not in (
select noseat
from dbo.booking
where statusbooking = 1
)
这是我的猜测。我不能说我真的明白 "noseat" 是什么意思(除非是 "number of seat")?