我正在制作一个浏览器黑手党游戏,并对列出所有家庭/帮派的页面进行编码。
每个家庭都有一个积分等级,由其所有成员现金、子弹、经验等的总和组成。
这是我循环显示家庭列表的代码:
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
然后在使用 PHP 的循环中,我计算出总分:
$points = $rs[sum_bullets]/500;
$points = $points + $rs[sum_cash]/10000;
$points = $points + $rs[sum_exp]/1000;
$points = $points + $rs[sum_ks];
现在谈这个问题。我想使用ORDER BY points DESC
. 我怎样才能调整我的查询来做到这一点?