Laravel 5 select with sum query exampleBy Hardik Savani | June 8, 2016 | | 7631 Viewer | Category : Laravel
Share this post:
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(). I give you both example you can see and use any one as perfect for you.
$data = DB::table("click")->sum('numberofclick');
$data = DB::table("click")
->select(DB::raw("SUM(numberofclick) as count"))
- PHP - How to implement Google new reCAPTCHA Code Example with Demo?
- Laravel 5 Repository Pattern Tutorial from scratch
- Laravel - How to make subquery in select statement?
- How to get site URL in Laravel 5?
- How to rename column name foreign key constraint in MySql Query?
- Laravel 5 - Bootstrap Admin Theme Integration example from scratch
- Laravel 5 Twitter OAuth using Socialite Package
- How to get last 2 days records from table using Mysql Query?