SQL Interview Question

What is an aggregate function in SQL?

Updated 2026-08-16 · Beginner friendly
Quick answer

An aggregate function takes many rows and returns a single summary value. The common ones are COUNT, SUM, AVG, MIN, and MAX. They are often used with GROUP BY to produce a summary per group, such as the total sales for each region.

Key takeaways
  • Aggregate functions compute a single value from a set of rows.
  • Common ones are COUNT, SUM, AVG, MIN, and MAX.
  • They are often paired with GROUP BY to summarise each group.

The common aggregates

SELECT region, SUM(amount) AS total
FROM sales
GROUP BY region;
-- one total per region

Without GROUP BY an aggregate summarises the whole table into one row. With GROUP BY it summarises each group separately.

In the interview

Watch the COUNT trap. COUNT(*) counts all rows, while COUNT(column) skips nulls in that column. Mentioning this difference shows you know how nulls quietly change results.

Frequently asked questions

Does COUNT include null values?

COUNT(*) counts all rows including nulls, while COUNT(column) counts only rows where that column is not null.

Can you filter on an aggregate result?

Yes, using HAVING after GROUP BY. For example, HAVING COUNT(*) greater than 5 keeps only groups with more than five rows.

Want the full SQL guide?

Read every SQL concept with notes, diagrams, and code in one place. Track your progress as you go.

Open the SQL guide All SQL questions