Advertisement

SQL Aggregations & Grouping interview questions and answers

7 SQL Aggregations & Grouping interview questions for SQL & Database Querying roles, each with a model answer, examples and likely follow-ups.

7 questions
Advertisement

7 questions

Q1 Beginner Save

What are SQL aggregate functions?

Functions summarizing data like SUM, COUNT, and AVG.
SUM(sales).
Real-world example
Using GROUP BY, an analyst calculated monthly revenue by region in seconds.
Likely follow-ups
  • What are aggregate functions
  • What is GROUP BY
  • What is HAVING
SQL Basics SQL Joins Advanced SQL
Q2 Beginner Save

What does GROUP BY do?

Groups rows for aggregation.
Example

Sales by region.

Real-world example
Using GROUP BY, an analyst calculated monthly revenue by region in seconds.
Likely follow-ups
  • What are aggregate functions
  • What is GROUP BY
  • What is HAVING
SQL Basics SQL Joins Advanced SQL
Q3 Beginner Save

What is HAVING in SQL?

Filters grouped results.
HAVING SUM(sales) > 1000.
Real-world example
Using GROUP BY, an analyst calculated monthly revenue by region in seconds.
Likely follow-ups
  • What are aggregate functions
  • What is GROUP BY
  • What is HAVING
SQL Basics SQL Joins Advanced SQL
Q4 Intermediate Save

What is COUNT DISTINCT?

Counts unique values.
Example

Unique customers.

Real-world example
Using GROUP BY, an analyst calculated monthly revenue by region in seconds.
Likely follow-ups
  • What are aggregate functions
  • What is GROUP BY
  • What is HAVING
SQL Basics SQL Joins Advanced SQL
Q5 Intermediate Save

What is the difference between WHERE and HAVING?

WHERE filters rows, HAVING filters groups.
Example

Filter totals.

Real-world example
Using GROUP BY, an analyst calculated monthly revenue by region in seconds.
Likely follow-ups
  • What are aggregate functions
  • What is GROUP BY
  • What is HAVING
SQL Basics SQL Joins Advanced SQL
Q6 Advanced Save

How do you calculate averages in SQL?

Use AVG function.
AVG(order_value).
Real-world example
Using GROUP BY, an analyst calculated monthly revenue by region in seconds.
Likely follow-ups
  • What are aggregate functions
  • What is GROUP BY
  • What is HAVING
SQL Basics SQL Joins Advanced SQL
Q7 Advanced Save

Why are aggregations useful?

Summarize large data.
Example

Total revenue.

Real-world example
Using GROUP BY, an analyst calculated monthly revenue by region in seconds.
Likely follow-ups
  • What are aggregate functions
  • What is GROUP BY
  • What is HAVING
SQL Basics SQL Joins Advanced SQL