Answers for "laravel select sum group by"

PHP
2

laravel sum group by

$docs = Document::groupBy('users_editor_id')
   ->selectRaw('sum(no_of_pages) as sum, users_editor_id')
   ->get(); //this return collection 

//In Blade
@foreach($docs as $doc)
	{{$doc->users_editor_id}} >-------< {{$doc->sum}}
@endforeach
Posted by: Guest on April-05-2021
1

sql select sum group by id laravel

Document::groupBy('users_editor_id')
   ->selectRaw('sum(no_of_pages) as sum, users_editor_id')
   ->pluck('sum','users_editor_id');

   // originally lists(), which was deprecated in favour of pluck in 5.2
   // and dropped completely in 5.3
   // ->lists('sum','users_editor_id');


// returns array like this:
array(
  users_editor_id => sum,
  ...
)
Posted by: Guest on July-14-2020
0

sql select sum group by id laravel join

$users = User::select('users*', 'analytics.*', DB::raw('SUM(analytics.revenue) As revenue'))
         ->leftJoin('analytics', 'analytics.user_id', '=', 'users.id')
         ->where('analytics.date', Carbon::today()->toDateString())
         ->get();
Posted by: Guest on July-14-2020

Browse Popular Code Answers by Language