Mám opakované záznamy (tučne) pre podmienky =1 a >1. Nerozumiem prečo.
T1 - prvá časť (Team1FK)
T2 - druhá časť. Po UNION (Team2FK)
COUNT(T.COUNTRYFK) je tu vo výsledku len kvôli kontrole. Samozrejme zodpovedá výsledku.
SELECT T.COUNTRYFK, C.TITLE, C.COUNTRYID, COUNT(T.COUNTRYFK)
FROM MATCHES M
INNER JOIN TEAMS T ON M.TEAM1FK = T.TEAMID
INNER JOIN COUNTRIES C ON T.COUNTRYFK = C.COUNTRYID
INNER JOIN ROUNDS R ON M.ROUNDFK = R.ROUNDID
WHERE R.SEASONFK = 8363 AND M.REMATCH = False
GROUP BY T.COUNTRYFK, C.TITLE, M.REMATCH, C.COUNTRYID
HAVING COUNT(T.COUNTRYFK) > 1
UNION
SELECT T.COUNTRYFK, C.TITLE, C.COUNTRYID, COUNT(T.COUNTRYFK)
FROM MATCHES M
INNER JOIN TEAMS T ON M.TEAM2FK = T.TEAMID
INNER JOIN COUNTRIES C ON T.COUNTRYFK = C.COUNTRYID
INNER JOIN ROUNDS R ON M.ROUNDFK = R.ROUNDID
WHERE R.SEASONFK = 8363 AND M.REMATCH = False
GROUP BY T.COUNTRYFK, C.TITLE, M.REMATCH, C.COUNTRYID
HAVING COUNT(T.COUNTRYFK) > 1
ORDER BY 2