php tp5有这样一个数组,多个学校得学生成绩在一哥表中
我已经计算出了每个人所考总分和总分排名,但是如何计算出每一个人在自己学校得排名呢?
php tp5有这样一个数组,多个学校得学生成绩在一哥表中
我已经计算出了每个人所考总分和总分排名,但是如何计算出每一个人在自己学校得排名呢?
sql写法
SELECT school, name,
RANK() OVER (PARTITION BY school ORDER BY a1 DESC) AS a1_rank,
RANK() OVER (PARTITION BY school ORDER BY a2 DESC) AS a2_rank
FROM scores;
tp写法
$result = Db::table('scores')
->field('school, name, RANK() OVER (PARTITION BY school ORDER BY a1 DESC) AS a1_rank, RANK() OVER (PARTITION BY school ORDER BY a2 DESC) AS a2_rank')
->order('school')
->select();
print_r($result);