Reputation: 3
I'm wondering if it is possible to take the sum of multiple fields in one query using the fluent query builder.
For exemple :
SELECT sum(nb_visit + nb_recommendation)
FROM Stats
GROUP BY id
So far is what i have :
Stats::sum('nb_visit+nb_recommendation');
Upvotes: 0
Views: 47
Reputation: 87789
You can use QueryBuilder to do this:
DB::table('stats')
->select(DB::raw('sum(nb_visit + nb_recommendation)'))
->groupBy('id')
->get();
Upvotes: 1