PaulM1985
July 18th, 2012, 01:21 PM
Hi
I am trying to output the following from my MySQL database:
player_id, number_of_wins, total_games
I am using:
SELECT player_id, SUM (money > opponents_money) as number_of_wins, COUNT(*) as total_games
FROM my_table
GROUP BY player_id
This works because it seems to promote (money > opponents_money) from TRUE/FALSE to 1/0, but I wanted to know if this is the right thing to do. Is it possible to put something in to explicitly say that money > opponents_money should be treated as 1 if true and 0 if false?
Paul
I am trying to output the following from my MySQL database:
player_id, number_of_wins, total_games
I am using:
SELECT player_id, SUM (money > opponents_money) as number_of_wins, COUNT(*) as total_games
FROM my_table
GROUP BY player_id
This works because it seems to promote (money > opponents_money) from TRUE/FALSE to 1/0, but I wanted to know if this is the right thing to do. Is it possible to put something in to explicitly say that money > opponents_money should be treated as 1 if true and 0 if false?
Paul