-
Notifications
You must be signed in to change notification settings - Fork 1
Aggregation
Gilberto Junior edited this page Nov 29, 2019
·
4 revisions
Count the number of rows.
public function count(): int;
$numRows = $repository
->where('active = 1')
->count();
echo $numRows . ' rows found';
Sum the field's value.
public function sum(string $column): mixed
$total = $repository
->where('category_id = 2')
->sum('price');
echo 'Total: ' . $total;
Get the maximun value from field.
public function max(string $column): mixed
$maximun = $repository
->where('paid_at IS NULL')
->max('canceled_at');
echo 'Max: ' . $maximun;
Get the minimun value from field.
public function min(string $column): mixed
$minimun = $repository
->min('birth_date');
echo 'Min: ' . $minimun;
Get the average from field.
public function avg(string $column): mixed
$average = $repository
->avg('age');
echo 'Average: ' . $average;
by c0dehappy