Search
 
SCRIPT & CODE EXAMPLE
 

SQL

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
Comment

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();
Comment

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,
  ...
)
Comment

PREVIOUS NEXT
Code Example
Sql :: import large .sql files into lampp 
Sql :: pl/sql loop example 
Sql :: create or replace table sql 
Sql :: create user sql server 
Sql :: mac install mysql 
Sql :: sql in array query 
Sql :: update using case in mysql 
Sql :: how to update random rows in sql 
Sql :: mysql alter table add column first 
Sql :: postgres float to int 
Sql :: sql delete row with auto increment 
Sql :: how to delete user in mysql 
Sql :: order by desc postgres 
Sql :: postgres concat 
Sql :: How to convert DateTime to VarChar SQL 
Sql :: Check user permissions on postgres database 
Sql :: restart sql server command line linux 
Sql :: not exists mysql 
Sql :: sql query to get the number of rows in a table 
Sql :: oracle sql select all days between two dates except weekends 
Sql :: greater than in mongodb query 
Sql :: show all event schedular on mysql 
Sql :: convert varchar column to int in sql server 
Sql :: mysql get latest duplicate rows 
Sql :: postgresql combine values in one field 
Sql :: ascending order and where in sql 
Sql :: declarative base sqlalchemy 
Sql :: mariadb json select 
Sql :: sql if clause within where clause 
Sql :: sql server add time to date 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =