SELECT SUM(ranked.score) AS scores, SUM(ranked.darts) AS darts, ranked.year, heim, gast, id, mdate FROM
(SELECT ls.score, ls.darts as darts, YEAR(`lg`.`mdate`) as YEAR, lg.heim, lg.gast, lg.id, lg.mdate ,@leground := IF(@tmpleg = leg, @leground + 1, 1) AS leground,
@tmpleg := leg
FROM #__livescore_score ls
INNER JOIN #__livescore_games lg ON ls.game = lg.id
INNER JOIN #__livescore_modus lm ON lg.rrmodus = lm.id
INNER JOIN #__livescore_roundrobin lrr ON lm.id = lrr.modus AND lrr.ordering = ls.spiel
WHERE ls.pass = 204 AND ls.darts>0 AND lrr.round = 'E' AND lg.finish = 1 AND Year(lg.mdate)=2019 ORDER BY ls.game, ls.spiel, ls.leg, ls.id) ranked
WHERE ranked.leground <= 3 GROUP BY ranked.year, ranked.mdate ORDER BY ranked.mdate