SQL Aggregate Functions

MIN, MAX, COUNT, SUM and AVG.

✍️ 3 exercises + code challenge in this lesson

Aggregate functions calculate one value from many rows:

  • COUNT(): number of rows (COUNT(*) counts all; COUNT(column) ignores NULLs).
  • SUM(): total.
  • AVG(): average.
  • MIN() / MAX(): smallest / largest.

Combine them with GROUP BY (a later lesson) to get one result per group.

Key Takeaways: SQL Aggregate Functions

Mastering SQL Aggregate Functions helps you write clean and reliable SQL code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

SQL Aggregate Functions Code Example

SQL
SELECT COUNT(*) AS Products,
       MIN(Price) AS Cheapest,
       MAX(Price) AS MostExpensive,
       ROUND(AVG(Price), 0) AS AveragePrice,
       SUM(Stock) AS TotalStock
FROM Products;

SELECT COUNT(Email) AS CustomersWithEmail FROM Customers;
Free sign-in required · Google login available

SQL Aggregate Functions Practice Exercises

Check what you learned in “SQL Aggregate Functions”.

/ 3 solved
Fill in the blank

Count the rows in Orders.

SELECT (*) FROM Orders;
✓ Correct! Not quite. Try again.
Multiple choice

Which function returns the average?

✓ Correct! Not quite. Try again.
Code challenge

Select the total stock of all products as TotalStock.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services