SELECT
a.id,
a.name,
a.player_count,
a.rating,
AVG(p.total_people_count) AS `average`
FROM p_alliances a
INNER JOIN p_players p ON (p.alliance_id = a.id)
GROUP BY a.id
ORDER BY a.rating DESC, a.player_count DESC, a.id ASC
LIMIT %s,%s
If there could be 0 players you might want to change INNER JOIN
to LEFT JOIN
, but it may impact performance in mysql.
1
solved Joining queries