我使用此查询显示一个人在比赛中担任裁判和助理裁判的次数。
然而,它似乎是将参考号乘以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;
感谢帮助。