The actual query that should be cared about is
Code: Select all
SELECT COUNT(*) FROM teams,users WHERE teams.Team_ID=users.Team_ID GROUP BY teams.Team_ID HAVING SUM(Betting_Points + Other_Points) > $team_points
$team_points = the total points the selected team has (don't care about it...)
I have to tables, users and teams. Users have betting points and other points and they can be negative.
With the query above I try to count the number of teams that have more points than the selected team.
The problem is the group by thing. Now it returns an individual COUNT(*) for each team because of the GROUP BY clause. And without the GROUP BY clause I can't use the SUM function so that it returns each teams total SUM.
With the query above I can use mysql_num_rows() to get the actual count I want to get, but it takes too much resources if I have many teams and users in the database.