2015-04-14 52 views
1

我有一個users表與一個整數字段被稱爲epLaravel排名字段如何在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) 

回答

相關問題