[Quote=引用 3 楼 fredrickhu 的回复:]
SQL code
--try
;with f as
(
select
*
from
主表 a
where
exists(select 1 from 参考表 where book_date=a.date and slot=a.slot)
)
select * from f t where wait=(select min(wait) where date=t.……
[/Quote]
好像不行,An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.
[Quote=引用 3 楼 fredrickhu 的回复:]
SQL code
--try
;with f as
(
select
*
from
主表 a
where
exists(select 1 from 参考表 where book_date=a.date and slot=a.slot)
)
select * from f t where wait=(select min(wait) where date=t.……
[/Quote]
这个select 1 是啥意思?我单独执行,选的全部是1啊
[Quote=引用 3 楼 fredrickhu 的回复:]
SQL code
--try
;with f as
(
select
*
from
主表 a
where
exists(select 1 from 参考表 where book_date=a.date and slot=a.slot)
)
select * from f t where wait=(select min(wait) where date=t.……
[/Quote]
谢谢先,我验证一下。。。
--try
;with f as
(
select
*
from
主表 a
where
exists(select 1 from 参考表 where book_date=a.date and slot=a.slot)
)
select * from f t where wait=(select min(wait) where date=t.date and slot=t.slot)