$model=DB::table('tablebname') ->where(function($query) use ($res){ $query->where('xx','xx'); }) ->selectRaw("area,from_unixtime(created_time,'%Y-%m-%d') as dates,sum(num) as use_num,path,desc") ->groupBy(['dates','area','path','money_id']) ->orderBy('dates','desc'); $data=DB::table(DB::raw("({$model->toSql()}) as temptable")) ->mergeBindings($model) ->paginate(15);