Hi, I am pretty new at this however now I am now completely stuck. I have 3 tables with the following fields.
Fixtures
FixID
RefID
Referees
RefID
Referee
Cards
FixID
Card
Currently I have query that counts the number of Yellow and Red cards, grouped by the referee:
SELECT Fixtures.RefID,Referees.Referee
, sum(if(Cards.Card='Yellow',1,0)) AS "Yellow Card"
, sum(if(Cards.Card='Red',1,0)) AS "Red Card"
, count(Cards.Card) as "Total"
FROM Referees INNER JOIN (Fixtures INNER JOIN Cards ON Fixtures.FixID = Cards.FixID) ON Referees.RefID = Fixtures.RefID
GROUP BY Fixtures.RefID, Referees.Referee
ORDER BY Total DESC;
The above works great, however what I want to do is also have the total number of games the Referee has done, I can do this in a seperate query:
SELECT Referees.RefID, Referees.Referee, Count(Fixtures.FixID) AS "NoGames"
FROM Referees
LEFT JOIN Fixtures ON Referees.RefID=Fixtures.RefID
GROUP BY Referees.RefID, Referees.Referee
ORDER BY NoGames DESC;
However when I try and add an extra column count in the first query to count/show the number of games the Ref has done it just returns the same total number of cards i.e the the same number as the column "Total"? Like so:
SELECT Fixtures.RefID,Referees.Referee
, sum(if(Cards.Card='Yellow',1,0)) AS "Yellow Card"
, sum(if(Cards.Card='Red',1,0)) AS "Red Card"
, count(Cards.Card) as "Total"
, [B]count(Fixtures.FixID) as "NoGames"[/B]
FROM Referees INNER JOIN (Fixtures INNER JOIN Cards ON Fixtures.FixID = Cards.FixID) ON Referees.RefID = Fixtures.RefID
GROUP BY Fixtures.RefID, Referees.Referee
ORDER BY Total DESC;
Can anybody help? Apologies if this does not make sense. 😕
Thanks in advance for any help given.
C.