SQL Aggregation Interview Questions

SQL Aggregation Interview Questions

Aggregation questions test whether you can summarize data at the right grain using GROUP BY and HAVING.

Common themes include COUNT vs COUNT(DISTINCT), conditional aggregation with CASE, and aggregating after joins.

Interviewers look for correct groupings, handling of NULLs, and clear explanation of your logic.

165Questions
47Companies
Easy 7 • Medium 158 • Hard 0Difficulty mix

Common SQL aggregation interview patterns

  • Choosing the correct grouping level
  • HAVING vs WHERE for post-aggregation filters
  • Conditional aggregation with CASE
  • COUNT(DISTINCT) vs COUNT
  • Aggregation after joins
  • Top N per group with aggregation

SQL aggregation interview questions

Filter and sort
All SQL questions

Common mistakes with SQL aggregation

  • Grouping by too many columns
  • Using WHERE instead of HAVING for aggregates
  • Double counting after joins
  • COUNT(column) skipping NULLs unintentionally
  • Misusing DISTINCT on aggregated fields

How aggregation questions are evaluated in interviews

Correct grouping and filtering matter more than micro-optimizations.

Explain your grain, especially when combining joins and aggregates.

Call out assumptions about NULLs and duplicates.

Related SQL concepts