Im making a browser mafia game, and coding the page where it lists all of the familys / gangs.
Each family has a points rating, made up of the combined SUMs of all its members cash, bullets, exp, etc.
This is my code to loop through to show the family listings:
SELECT
(SELECT COUNT(*) FROM players WHERE status='alive' AND family=f.id) as member_count,
(SELECT SUM(bullets) FROM players WHERE status='alive' AND family=f.id) as sum_bullets,
(SELECT SUM(cash) FROM players WHERE status='alive' AND family=f.id) as sum_cash,
(SELECT SUM(exp) FROM players WHERE status='alive' AND family=f.id) as sum_exp,
(SELECT SUM(killscore) FROM players WHERE status='alive' AND family=f.id) as sum_ks,
name, id FROM familys f
then during the loop with PHP I work out the total points:
$points = $rs[sum_bullets]/500;
$points = $points + $rs[sum_cash]/10000;
$points = $points + $rs[sum_exp]/1000;
$points = $points + $rs[sum_ks];
Now onto the question. I want to order the results using ORDER BY points DESC. How can I adjust my query to do this?
try to shift logic from application to MySQL to make it faster with a single query as:
Edit: for output of total_points