📊 Aggregate Functions in SQL

Last Updated: January 2026


The AGGREGATE FUNCTION is a function that operates on multiple rows and returns a single value.

  • Use to summarize data.
  • Commonly used with GROUP BY clause.

Most Common Aggregate Functions

COUNT()

  • Returns the number of rows in a table or a result set.
  • It not Count NULL values.
  • Count Null values also, use COUNT(*)
SELECT COUNT(*) FROM table_name;
-- OR
SELECT COUNT(column_name) FROM table_name;

SUM()

  • Returns the sum of all values in a column.
  • Also Pass an expression.
SELECT SUM(column_name) FROM table_name;
-- OR
SELECT SUM(column_name + 1) FROM table_name;

AVG()

  • Returns the average of all values in a column.
  • Also Pass an expression.
SELECT AVG(column_name) FROM table_name;
-- OR
SELECT AVG(column_name * 2) FROM table_name;

MAX()

  • Returns the largest value in a column or rows.
SELECT MAX(column_name) FROM table_name;

MIN()

  • Returns the smallest value in a column or rows.
SELECT MIN(column_name) FROM table_name;