Laravel Select with Sum Query Example

Laravel Select with Sum Query Example

Hello friends, Today we will show Laravel query builder sum group by. Here you will show simple example of laravel select sum of column. we will provide get sum of amount, visitor etc in laravel. we will explain select sum laravel eloquent, laravel sum query with where condition and laravel select sum of column.

Example 1:

$data = DB::table("click")->sum('numberofclick');
print_r($data);

Example 2:

$data = DB::table("click")
        ->select(DB::raw("SUM(numberofclick) as count"))
        ->orderBy("created_at")
        ->groupBy(DB::raw("year(created_at)"))
        ->get();
print_r($data);

I hope you understand of laravel DB::row sum query and it can help you..

Read Also :  Laravel Arr last() function Example