Laravel aggregate functions; Through this tutorial, i am going to show you how to use the laravel aggregate AVG, COUNT, SUM, MIN, MAX functions with query.
Laravel Aggregate Function: SUM, AVG, MAX, MIN, COUNT
See the list of laravel aggregate functions with query; as follows:
- Laravel COUNT() Function
- Laravel SUM() Function
- Laravel AVG() Function
- Laravel MAX() Function
- Laravel MIN() Function
Laravel COUNT() Function
In laravel, the COUNT () function is used to return the count of given columns.
Laravel Count() Function Query Example
$users = DB::table('users')->count();
The above example return the count of rows the given column name first_name from the database table.
Laravel SUM() Function
In Laravel, the SUM() function is used to return the total sum of given columns.
Laravel SUM() Function Query Example
$data = DB::table("click")->sum('numberofclick');
Laravel AVG() Function
In laravel, the AVG() function is used to return the average value given columns in query.
Laravel AVG() Function Query Example
$price = DB::table('orders') ->where('finalized', 1) ->avg('price');
Laravel MAX() Function
In laravel, the MAX() function is used to return the maximum value of given columns in query.
Laravel MAX() Function Query Example
$price = DB::table('orders')->max('price');
Laravel MIN() Function
In laravel, the MIN() function is used to return the mininum value of given columns in query.
Laravel MIN() Function Query Example
$price = DB::table('orders')->min('price');
Conclusion
Laravel aggregate function tutorial, You have learned what is types of aggregate functions in laravel and how to use it in laravel apps.