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

Roles this comes up in

Companies these come from

Other topics