mysql分数占百分比查询

select count(1) as 排名 from 表名 where 分数字段 >= (select 分数字段 from 表名 where 姓名字段 = '用户名')


微擎写法

$uscore = pdo_fetch("SELECT score FROM ".tablename('game_list')." WHERE open_id = :open_id LIMIT 1", array(':open_id' => $openid));
$total = pdo_fetch("SELECT count(1) as total FROM ".tablename('game_list')." WHERE score = :score LIMIT 1", array(':score' => $uscore['score']));
$hhl=round(($total['total']/$user_total)*100).'%';

你可能感兴趣的:(微擎,mysql,百分比,分数,成绩)