Skip to content

Examples

Benyamin Khalife edited this page Nov 18, 2023 · 5 revisions

Example: Get the number of rows along with the total value of the percent field

SELECT SUM(`percent` as 'sum'), count(*) as 'count' WHERE `client_id` = :client_id

$result = UserActivity::select(function($s){
            $s->sum('percent')->as('sum');
            $s->count()->as('count');
          })
          ->where('client_id', $client->id)
          ->first();

Output:

{"sum": 160, "count": 3}

Clone this wiki locally