I am using a MySQL database and I have a big mysql_query that works completely fine except for this one line.
SELECT game_id,
COALESCE(
SUM(CASE WHEN game_score = 1 THEN 1 ELSE 0 END)
-
SUM(CASE WHEN game_score = 0 THEN 1 ELSE 0 END), 0) AS score
FROM ....
WHERE ....
GROUP BY ....
This line returns me almost all of the numbers that I want, yet they are the same numbers as when I wasn’t using the COALESCE function.
I would like this statement to return me 0 when there is a game_id that has an emptygame_score` field.
Where is my code going wrong?
you can also use decode function like this —
I have checked this query for working, its fine
hope it helps you….