List some Aggregates methods provided by query builder in Laravel ?

Technology CommunityCategory: LaravelList some Aggregates methods provided by query builder in Laravel ?
VietMX Staff asked 3 years ago

Aggregate function is a function where the values of multiple rows are grouped together as input on certain criteria to form a single value of more significant meaning or measurements such as a set, a bag or a list.

Below is list of some Aggregates methods provided by Laravel query builder:

  • count()
$products = DB::table(‘products’)->count();
  • max()
    $price = DB::table(‘orders’)->max(‘price’);
  • min()
    $price = DB::table(‘orders’)->min(‘price’);
  • avg()
    *$price = DB::table(‘orders’)->avg(‘price’);
  • sum()
    $price = DB::table(‘orders’)->sum(‘price’);