1
我有一个users
表与一个整数字段被称为ep
。Laravel排名字段如何在MySQL中使用设置变量?
现在,我想检索由EP字段排序的特定组中的所有用户,以及生成的名为rank
的MySQL字段。
这是我的尝试:
DB::transaction(function()
{
DB::statement("SET @rank:=0");
$group = Sentry::findGroupByName('Player');
$users = Sentry::getUserProvider()->createModel()
->join('throttle', 'throttle.user_id', '=', 'users.id')
->join('users_groups', 'users_groups.user_id', '=', 'users.id')
->where('throttle.banned', 0)
->where('throttle.suspended', 0)
->where('users_groups.group_id', $group->id)
->orderBy('ep', 'desc')
->paginate(100, array('@rank := @rank + 1', 'users.ep', 'users.username'));
});
但我得到这个错误:
SQLSTATE[42S22]: Column not found: 1054 Unknown column '@rank := @rank + 1' in 'field list' (SQL: select `@rank := @rank + 1`, `users`.`ep`, `users`.`username` from `users` inner join `throttle` on `throttle`.`user_id` = `users`.`id` inner join `users_groups` on `users_groups`.`user_id` = `users`.`id` where `throttle`.`banned` = 0 and `throttle`.`suspended` = 0 and `users_groups`.`group_id` = 2 order by `ep` desc limit 100 offset 0)