calculate using in-query values I'm attempting to perform a calculation at the query level and have run into
the following problem.
I would like to calculate a percentage using the SUM totals of two other
values. I assume these need to be assigned to variables, but am unaware of
the correct syntax. Can someone clue me in? Thanks.
SELECT mr.teamid,
SUM( IF( mr.winner = '1', 1, 0 ) ) AS wins,
SUM( IF( mr.winner = '0', 1, 0 ) ) AS losses,
SUM(wins/losses) AS percentage <----- how to correctly calculate
FROM match_result mr
GROUP BY mr.teamid |