Select g.Group as "итог",
sum(t.y) as "сумма"
From groups g
Join table t
On g.x = t.x
Group by g.Group
SELECT companies.name, max(polls.created_at)
FROM companies
JOIN teams
ON teams.company_id = companies.id
LEFT
JOIN polls
ON polls.team_id = teams.id
GROUP BY companies.name
ORDER BY 2