AnalystPracticeGuides
DashboardSign up

SQL SUM, AVG, MIN and MAX

Aggregate functions turn many rows into one number. SUM adds, AVG averages, MIN and MAX return the lowest and highest value. All of them ignore NULLs.

Watch it solved. Q4: an average with gaps (NULL and COALESCE), from 2:22, in our video “SQL Interview Questions and Answers for Data Analysts (Easy to Hard)”. Pressing play loads the video from YouTube (privacy). Open on YouTube

How do you use them together?

SELECT COUNT(*) AS orders,
SUM(amount) AS revenue,
ROUND(AVG(amount), 2) AS avg_order,
MIN(order_date) AS first_order,
MAX(order_date) AS last_order
FROM orders;

MIN and MAX also work on dates and text.

Why is my average a whole number?

In some databases, such as SQL Server and PostgreSQL, dividing two integers gives an integer: SUM(x) / COUNT(*) can drop the decimals. Use AVG, or multiply by 1.0 first. SQLite's AVG always returns a decimal number.

How do you find the row with the maximum?

MAX(amount) gives the value, not the order. To get the whole row:

SELECT * FROM orders
WHERE amount = (SELECT MAX(amount) FROM orders);

Why don't the totals match my spreadsheet?

Usually NULLs (ignored), duplicates from a join (counted twice), or a filter in WHERE that you forgot about.

Try it yourself. Practise this in a real database in your browser, with instant feedback.
Practise AVG and SUM Practise MIN and MAX

Updated November 2026.

← All free guides