Jump to content

[SOLVED] Query Order won't work


Mutley

Recommended Posts

I have a query that I want to order by a total score.

 

It adds up 4 fields for every user of that team. However it doesn't order them by highest total score, just randomly.

 

			$sql = "SELECT t.team_id, t.level, t.name, t.initials, t.owner, l.user_id, SUM(l.2playerpts) AS vr2playerpts, SUM(l.4playerpts) AS vr4playerpts,SUM(l.6playerpts) AS vr6playerpts, SUM(l.8playerpts) AS vr8playerpts, l.wins, l.losses, u.user_id, u.team_id
		FROM teams t
		INNER JOIN users u ON u.team_id = t.team_id
		INNER JOIN leaderboard l ON l.user_id = u.user_id
		GROUP BY t.team_id
		ORDER BY (SUM(l.2playerpts) + SUM(l.4playerpts) + SUM(l.6playerpts) + SUM(l.8playerpts)) AND t.level DESC";

 

Any ideas? I've tried removing the SUM statement and also using the AS statement versions but still seems random.

 

Thanks,

Nick.

Link to comment
https://forums.phpfreaks.com/topic/131534-solved-query-order-wont-work/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.