以下是我的发言:
select TournamentID, TournamentDateTime, TournamentName, TournamentTypeName, BossTournamentID
from vwTournaments
where tournamentid in
(
select distinct(fk_tournamentid)
from tournamentprizes
where place between 1
and (select max(numranks) from tournaments)
and fk_winnerid is not null
)
and TournamentDateTime > '8/29/2013'
and
(
TournamentID like '%%'
or TournamentDateTime like '%%'
or BossTournamentID like '%%'
or TournamentTypeName like '%%'
or TournamentName like '%%'
)
order by TournamentDateTime DESC
需要修复的部分是“并且fk_winnerid不为空”“我想要说明所有锦标赛奖品是否有非空的fk_winnerid。不只是一个奖项。
答案 0 :(得分:1)
如果我理解正确,您需要一个相关的EXISTS
子查询:
from vwTournaments AS t
where NOT EXISTS
(
select 1
from tournamentprizes
where fk_tournamentid = t.tournamentid
and place between 1
and (select max(numranks) from tournaments)
and fk_winnerid IS NULL
)
and TournamentDateTime > '20130829'
and ...