1. 程式人生 > >laravel sum多欄位

laravel sum多欄位

1、單個欄位
 DB::table('table_name')
       ->where('uid',$uid)
       ->sum('likes');

2、多個欄位

$post_datas = DB::table('table_name')
      ->where('uid',$uid)
      ->first(
         array(
            \DB::raw('SUM(shares) as shares'),
            \DB::raw('SUM(comments) as comments'),
            \DB::raw('SUM(likes) as likes')
               )
            );