Assignment Query Desk
compares basketball strength at the country level using distinct club counts and winning records.
Query brief
Countries with multiple clubs and strong average records.
capture the result grid in phpMyAdmin after running the query.
SELECT
c.country_name,
COUNT(DISTINCT t.team_id) AS clubs,
ROUND(AVG(ts.wins), 1) AS avg_wins,
ROUND(AVG(ts.wins / NULLIF(ts.wins + ts.losses, 0)), 3) AS avg_win_pct
FROM countries c
INNER JOIN teams t ON t.country_id = c.country_id
INNER JOIN team_seasons ts ON ts.team_id = t.team_id
GROUP BY c.country_id, c.country_name
HAVING COUNT(DISTINCT t.team_id) >= 2 AND AVG(ts.wins) >= 12
ORDER BY avg_win_pct DESC, clubs DESC;
Live result
| Country Name | Clubs | Avg Wins | Avg Win Pct |
|---|---|---|---|
| France | 2 | 12.1 | 0.452 |