我有3张桌子:
我试图为每个球队取得特定赛季的胜利数量(本例中为2015年)。
这就是我目前所拥有的,但它为所有球队返回0。
我的SQL语法:
SELECT T.name, count(a.victory) as Wins
FROM Teams T, Seasons S
LEFT JOIN
(SELECT TS.id_team, TS.victory FROM Teams_Stats TS WHERE TS.victory = 1) a
ON a.id_team = 'T.id_team'
WHERE T.id_season = S.id_season AND S.name = '2015'
GROUP BY T.nom
ORDER BY T.nom
我做错了什么?
谢谢:)
答案 0 :(得分:0)
尝试修改您的查询有点像
SELECT T.name, count(TS.victory) as Wins
FROM Teams T
JOIN Seasons S ON T.id_season = S.id_season AND S.name = '2015'
LEFT JOIN Teams_Stats TS ON TS.id_team = T.id_team AND TS.victory = 1
GROUP BY T.name
ORDER BY T.name