Код: Выделить всё
SELECT teams.team_name, SUM(team_scores.score) AS total_score FROM teams LEFT JOIN team_scores ON team_scores.team_id = teams.id WHERE teams.organisation_id = ? GROUP BY teams.domain_name
< /code>
Хороший и простой, и он работает, возвращая «полную оценку» наряду с именем команды.$teams = DB::select('SELECT teams.team_name, SUM(team_scores.score) AS total_score FROM teams LEFT JOIN team_scores ON team_scores.team_id = teams.id WHERE teams.organisation_id = ? GROUP BY teams.domain_name', [$organisation_id]);
Подробнее здесь: https://stackoverflow.com/questions/797 ... t-return-n