SELECT teamname FROM
(
SELECT teamname, COUNT(played) AS games_won FROM
(
SELECT teamname, played FROM
(
SELECT teamnamehost AS teamname, teamnamevisitor AS played
FROM game WHERE scorehost > scorevisitor
UNION ALL SELECT teamnamevisitor AS team, teamnamehost AS played
FROM game WHERE scorevisitor > scorehost
) b
ORDER BY teamname
)
GROUP BY teamname
)
WHERE games_won =
(
SELECT MAX(games_won) AS games_won FROM
(
SELECT teamname, COUNT(played) AS games_won FROM
(
SELECT teamname, played FROM
(
SELECT teamnamehost AS teamname, teamnamevisitor AS played
FROM game WHERE scorehost > scorevisitor
UNION ALL SELECT teamnamevisitor AS team, teamnamehost AS played
FROM game WHERE scorevisitor > scorehost
) b
ORDER BY teamname
) b
GROUP BY teamname
)
);