表评分足球

时间:2016-02-01 00:52:13

标签: php mysql

我有三张桌子:俱乐部,目标和积分。当我完成目标和积分的总和时,它给了我双倍的结果。我找了一个解决方案MySQL doubled results using sum and left join,但我们现在显示:1054 - 'on clause'中的未知列'b.idKlub'SQL = SELECT ...我的错误在哪里?

SELECT
k.imeKluba, 
b.odigrano_kola, b.pobeda, b.nereseno, b.izgubljeno, b.ukupni_bodovi,
g.dati_golovi, g.primljeni_golovi, g.razlika_golovi
FROM #__fudbal_klubovi AS k 
LEFT JOIN (SELECT
        COUNT( idKolo) AS odigrano_kola,
        COUNT(IF(bodovi = 3, 1, NULL)) AS pobeda, 
        COUNT(IF(bodovi = 1, 1, NULL)) AS nereseno, 
        COUNT(IF(bodovi = 0, 1, NULL)) AS izgubljeno, 
        SUM(bodovi) AS ukupni_bodovi
    FROM #__fudbal_bodovi
    GROUP BY idKlub) AS b
    ON b.idKlub = k.idKlub 
LEFT JOIN (SELECT
        SUM(go) AS dati_golovi,
        SUM(go_p) AS primljeni_golovi,
        SUM(go) - SUM(go_p) AS razlika_golovi
    FROM #__fudbal_gol
    GROUP BY idKlub) AS g
    ON g.idKlub = k.idKlub

0 个答案:

没有答案