Cara Menggunakan Sum Di Laravel
Posted on
We mostly required to get sum of amount, salary etc in laravel. We can also get sum of column using mysql SUM.
We have two way to get sum of column value. First we can use laravel sum of query builder and another one we can use with directly with select statement using DB::raw.
Cara Menggunakan Sum Di Laravel Number
I give you both example you can see and use any one as perfect for you.Example 1:$data = DB::table('click')-sum('numberofclick');printr($data);Example 2:$data = DB::table('click')-select(DB::raw('SUM(numberofclick) as count'))-orderBy('createdat')-groupBy(DB::raw('year(createdat)'))-get;printr($data).