Ik heb al een topic geopend eerder over het zelfde ding. Alleen is dat probleem al opgelost. Nu zit ik met het volgende probleem. Ik probeer een telling te maken van hoeveel wedstrijden elk team gespeeld heeft. Ik kom hier niet aan uit.
Telling:
Dat werkt dus niet. Krijg ik een verkeerd getal. Wat doe ik fout?
Query zonder telling:
Telling:
PHP:
1
| count(home_game.home_score)+count(away_game.away_score) AS games |
Dat werkt dus niet. Krijg ik een verkeerd getal. Wat doe ik fout?
Query zonder telling:
PHP:
1
2
3
4
5
6
7
| SELECT team.name, coalesce( SUM( home_game.home_score ) , 0 ) + coalesce( SUM( away_game.away_score ) , 0 ) AS runs_scored, coalesce( SUM( home_game.away_score ) , 0 ) + coalesce( SUM( away_game.home_score ) , 0 ) AS runs_lost, ( coalesce( SUM( home_game.home_score ) , 0 ) + coalesce( SUM( away_game.away_score ) , 0 ) ) - ( coalesce( SUM( home_game.away_score ) , 0 ) + coalesce( SUM( away_game.home_score ) , 0 ) ) AS saldo, count( home_game.home_score ) + count( home_game.away_score ) AS test FROM `team` LEFT JOIN game AS home_game ON ( home_game.home_team = team.id ) LEFT JOIN game AS away_game ON ( away_game.away_team = team.id ) GROUP BY team.id |