SQL Query似乎会增加结果?

时间:2018-02-09 21:05:23

标签: mysql sql

我使用此查询显示一个人在比赛中担任裁判和助理裁判的次数。

然而,它似乎是将参考号乘以AR号,所以如果它应该是11& 6,它说66&我不明白为什么? (对于有经验的编码员来说,这可能非常明显):

SELECT CONCAT (lastname,', ',firstname),
    A.gender,
    DATE_FORMAT(dob, '%d %b %y'),
    DATE_FORMAT(dod, '%d %b %y'),
    CASE 
        WHEN NOT dod = '0000-00-00'
            THEN TIMESTAMPDIFF(year, dob, dod)
        ELSE TIMESTAMPDIFF(year, dob, Curdate())
        END,
    B.NAME,
    COUNT(M.REF),
    COUNT(M1.AR1),
    refID
FROM refs A
    LEFT JOIN teams B
        ON A.Nationality = B.TeamID
    LEFT JOIN matches M
        ON A.refID = M.REF
    LEFT JOIN matches M1
        ON A.refID = M1.AR1
GROUP BY A.refID
ORDER BY lastname;

感谢帮助。

0 个答案:

没有答案