Answer the question
In order to leave comments, you need to log in
Multiple SUM in laravel (Eloquent, MySQL) - how to do it right?
It is necessary to SUM over a large number of fields, I do this
$qry = Model::where(...)-> .....
->addSelect($DB->raw('contractor_id,
sum(`credit`) as `credit`, sum(`income`) as `income`, ...... sum(`active`) as `active`,
'));
$balance = $qry->first();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question