
February 4th, 2004, 06:34 AM
|
|
Contributing User
|
|
Join Date: Apr 2007
Posts: 19
Time spent in forums: 4 m 42 sec
Reputation Power: 0
|
|
|
query help count()
Hello:
Can someone please help me with this mysql query. For example if I had the a table with the below information I want to get the count of wins and losses. Does anyone know if there is away I can get the numbers if I dont have the fields 'Wins' and 'Losses'. I would like to get the numbers based on the 'Result'.
php Code:
Original
- php Code |
|
|
|
+------+------+--------+--------+ | Name | Wins | Losses | Result | +------+------+--------+--------+ | John | 1 | 0 | W | +------+------+--------+--------+ | John | 1 | 0 | W | +------+------+--------+--------+ | John | 0 | 1 | L | +------+------+--------+--------+ | John | 0 | 1 | L | +------+------+--------+--------+ | John | 1 | 0 | W | +------+------+--------+--------+ | John | 1 | 0 | W | +------+------+--------+--------+ | John | 1 | 0 | W | +------+------+--------+--------+ | John | 0 | 1 | L | +------+------+--------+--------+ | John | 1 | 0 | W | +------+------+--------+--------+ -> FROM Table -> WHERE 1=1 -> GROUP BY Name reslt> +------+------+--------+ | Name | Wins | Losses | +------+------+--------+ | John | 6 | 3 | +------+------+--------+
Does anyone one know how I can get the count based on the Result?
mysql> SELECT Name, COUNT(Result='W') AS Wins, COUNT(Result='L') As Losses
-> FROM Table
-> WHERE 1=1
-> GROUP BY Name
|