我有一个匹配表,其中包含winsteamid和stadiumid作为属性, 我需要找回在同一个体育场内赢得所有比赛的winteamid。
我尝试了这个,而且我还得到了其他不需要的行:
[]
答案 0 :(得分:0)
你应该用这个:
SELECT MAX(winningteamid)
FROM (
SELECT DISTINCT winningteamid, stadiumid
FROM match
)
GROUP BY stadiumid
HAVING COUNT(*) = 1;
答案 1 :(得分:0)
请试试(请说明您使用的是哪种RDBMS):
with cte as (
select winningteamid, stadiumid, count(stadiumid) over (partition by winningteamid) as count
from match
group by winningteamid, stadiumid
)
select * from cte where count = 1;
答案 2 :(得分:0)
我认为这就像使用HAVING
验证只有一个不同的体育场一样简单:
select winningteamid
from match
group by winningteamid
having count(distinct stadiumid) = 1