22,209
社区成员
发帖
与我相关
我的任务
分享
建议不要使用all
and @bookingTimeUp < (
select min(BookingTime) from
(
select BookingTime from [Booking] b1
inner join [BookingTable] bt2 on b1.ID = bt2.[Booking]
where bt2.[Table] = t.ID
) A
)
--这样应该可以在其他地方使用表a
--你试试吧,不行就把数据插入到一个临时表或者便量表中使用
建议不要使用all
and @bookingTimeUp < (
select min(BookingTime) from
(
select BookingTime from [Booking] b1
inner join [BookingTable] bt2 on b1.ID = bt2.[Booking]
where bt2.[Table] = t.ID
) A
)
--这样应该可以在其他地方使用表a
--你试试吧,不行就把数据插入到一个临时表或者便量表中使用
and @bookingTimeUp < all(
select BookingTime from
(
select BookingTime from [Booking] b1
inner join [BookingTable] bt2 on b1.ID = bt2.[Booking]
where bt2.[Table] = t.ID
) A
)
select min(BookingTime) from [Booking] b1
inner join [BookingTable] bt2 on b1.ID = bt2.[Booking]
where bt2.[Table] = t.ID
declare @sId uniqueidentifier, @free int ,@booked int, @bookingTimeUp datetime
set @sId = '8F0EC5C0-7839-4C24-8974-9738F2C0F1DA'
set @free = 1
set @booked = 2
set @bookingTimeUp = getdate()
select
t.TableName
from
[Table] t
inner join
[TableType] tt
on t.[TableType]=tt.ID
inner join
[Shop] s
on tt.[Shop]= s.ID
inner join
[BookingTable] bt
on t.ID=bt.[Table]
inner join
[Booking] b
on bt.[Booking]=b.ID
where s.ID=@sId and (
(t.State=@free) or
(t.State=@booked and @bookingTimeUp <
(select min(BookingTime) from [Booking] b1
inner join [BookingTable] bt2 on b1.ID = bt2.[Booking]
where bt2.[Table] = t.ID) )
)