請告訴我該怎麼辦這一關正確的查詢使用原始表達式Laravel 4
select @a:=POW(max(count_votes), 1/10) from users;
select id,name,raiting, count_votes, ((LOG(@a,count_votes))+raiting)/2 as actual_raiting from users order by actual_raiting desc ;
試過這樣
$rating = DB::statement('select @a:=POW(max(count_votes), 1/10) from users;
select id,name,raiting, count_votes, ((LOG(@a,count_votes))+raiting)/2 as actual_raiting from users order by actual_raiting desc; ');
return $rating;
和
$rating = DB::table('users')
->select(DB::raw('*, @a:=POW(max(count_votes), 1/10) '))
->select(DB::raw('*,raiting, count_votes, ((LOG(@a,count_votes))+raiting)/2 as actual_raiting'))
->orderBy("actual_raiting")
->get();
return $rating;
我究竟做錯了什麼?
PS:我的英語水平
謝謝!它幫助我 – Rai 2015-02-09 08:27:28
不客氣。如果這有效,請[標記爲已接受](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work)。如果不是,請告訴我應該更改/編輯或添加自己的答案:) – lukasgeiter 2015-02-09 08:30:00
如何僅獲取字段'actual_rating'? 他告訴我要返回所有數據 – Rai 2015-02-09 08:36:12