1

这是我的声明:

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。不只是一个奖项。

4

1 回答 1

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 ...
于 2013-09-05T19:06:43.473 回答