Topics / 🐍 Python Foundations / 🕵️ Level 6: Finding Odd Data: Filters, Sets, Z-Scores

SQL exercise · about 5 minutes · free

Above-Average Killers (Subquery)

Is this player suspicious, or just good? Compare each one with the average of everyone.

A subquery is a query inside another query. Here it calculates a number, the average, that the outer query compares against.

... HAVING SUM(kills) > (SELECT AVG(t) FROM (SELECT SUM(kills) AS t FROM matches GROUP BY player_id))
Bar chart: Kai 14, Mia 25, Zed 27, Ali 5, Nova 20, Bot9 58. the subquery computes the average; HAVING keeps players above it14Kai25Mia27Zed5Ali20Nova58Bot9average ≈ 24.8the subquery computes the average; HAVING keeps players above it
Your quest: Show each name and total_kills for players whose total kills are above the average player's total.
Starter code
-- outer query + subquery
-- Run this first to see the players table, then change it to answer the task.
SELECT *
FROM players
LIMIT 5;

Try it in your browser → Free. Sign in with Google to run it. Your code runs on your device.

In this level you'll learn:
More in Level 6: Finding Odd Data: Filters, Sets, Z-Scores

Share on LinkedIn