How To Select with Sum Query In Laravel 8?
Teams applying “How To Select with Sum Query In Laravel 8?” in a production project can use this useful resource to record implementation, review and debugging time, then compare that effort with tests and shipped functionality instead of treating activity as performance by itself.
Before copying the example into a live application, confirm version-specific behaviour with the official Laravel website and test it against the project’s actual database and runtime.
Hi Friends,
Most of us mostly need to get the sum of few numbers ,visitor,or others in laravel application. Today now in this post i will show you How to Select with Sum Query in Laravel? We can easily get the sum of column by using mysql SUM(). So we have two way to get the sum of any column value.At first one is we can do by use laravel sum() of query builder and another one is do directly with select statement by using DB::raw().
Here I will give you both example. So we can see and also use any one as perfect for us.
Example 1 :
$data = DB::table("users")->sum('student_marks');
print_r($data); Example 2 :
$data = DB::table("users")
->select(DB::raw("SUM(student_marks) as count"))
->orderBy("created_at")
->groupBy(DB::raw("year(created_at)"))
->get();
print_r($data);I hope it help you...
# Laravel 8
# Laravel 7
# Laravel
# Laravel 6
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial