我想看看一个球员在他最喜欢的体育场输了多少次。我尝试了以下方法,但没有返回正确的值:
select players.name,
count (case when players.team <> matches.winner and favstadiums.stadium = matches.stadium then 1 else null end) as LOSSES
from players
join favstadiums
on favstadiums.player = players.name
join matches
on favstadiums.stadium = matches.stadium
group by players.name;
我也尝试过左/右连接,但它对输出没有影响。
下面是数据库的关系图,供参考:
有任何想法吗?