按顺序计算两列的总和 - laravel

时间:2018-06-15 11:14:03

标签: php mysql laravel

我试图将下面的mysql查询转换为laravel等效。

select email from emails 
order by call_count + receive_count desc;

到Laravel

DB::table('emails')
->select('email')
->orderBy(SUM('call_count','receive_count'), 'DESC')
->get();

请让我知道..谢谢

1 个答案:

答案 0 :(得分:2)

试试这个

DB::table('emails')
    ->select('email')
    ->orderBy(DB::raw("`call_count` + `receive_count`"), 'desc')
    ->get();