Aggregations
SQL Aggregation Interview Questions
Aggregations collapse many rows into one per group: a total per customer, a count per month, an average per city. Most analytics questions are an aggregation with a condition attached somewhere.
What aggregation questions ask you to do
Across the questions here, these are the shapes that come up:
- Produce a total and a count for each group
- Keep only the groups above a threshold
- Count distinct values rather than rows
- Count only the rows meeting a condition, inside each group
- Average a column that has missing values in it
Common mistakes with aggregations
Conditions on rows and conditions on groups go in different places. WHERE filters rows before they are grouped, HAVING filters the groups afterwards, and swapping them does not raise an error — it just returns a different answer. Counting a specific column also skips empty values, where counting rows does not.
Questions to practice
- Completed trips by cityPandas
Ubereasy - Items and aisles per orderPandas
Instacarteasy - Listening minutes per listenerPandas
Pandoraeasy - Orders by statusSQL
Targeteasy - Orders per customerSQL
Targeteasy - Revenue by categoryPandas
Amazoneasy - Total completed revenueSQL
Walmarteasy - Customers with repeat ordersSQL
Targetmedium - Department headcount and paySQL
Salesforcemedium - Low-rated driversSQL
Ubermedium - Merchants with high fraud ratesSQL
Mastercardmedium - Missed minimum paymentsSQLPremium
Capital Onemedium - Card-testing patternsSQLPremium
Mastercardhard - Monthly completed revenueSQL
Stripehard
Questions last reviewed 19 October 2026.