Trying to create a query that gives me the total wins, draws and losses. I have the following query
SELECT CASE
WHEN m.home_team = '192'
AND m.home_full_time_score > m.away_full_time_score
OR m.away_team = '192'
AND m.home_full_time_score < m.away_full_time_score
THEN 1
END AS 'wins',
CASE
WHEN m.home_team = '192'
AND m.home_full_time_score = m.away_full_time_score
OR m.away_team = '192'
AND m.home_full_time_score = m.away_full_time_score
THEN 1
END AS 'draws',
CASE
WHEN m.home_team = '192'
AND m.home_full_time_score < m.away_full_time_score
OR m.away_team = '192'
AND m.home_full_time_score > m.away_full_time_score
THEN 1
END AS 'loss'
FROM exp_tm_matches m
INNER JOIN exp_tm_division_matches dm
ON (dm.match = m.id)
INNER JOIN exp_tm_divisions d
ON (dm.division = d.id)
WHERE m.info = 'PL'
AND (
m.home_team = '192'
OR m.away_team = '192'
)
AND dm.season = '16'
ORDER BY m.kick_off DESC LIMIT 5
This produces the following
wins draws loses
NULL 1 NULL
1 NULL NULL
1 NULL NULL
Null 1 NULL
1 NULL NULL
What I am trying to get is Wins = 3 Draws = 2 Loses = 0, If I add count to the case statements It ignores the LIMIT of 5.