Database Management System (DBMS)
Aggregation Functions in SQL

What are Aggregation Functions?

Aggregation functions in SQL are built-in functions that perform a calculation on a set of values and return a single value. These are commonly used with GROUP BY to summarize large datasets, such as totals, averages, maximum values, etc.


Common Aggregate Functions:

1. COUNT()

Purpose: Counts the number of rows.

 

Syntax:

SELECT COUNT(*) FROM Students;

 

Example: Count how many students are in the table.


2. SUM()

Purpose: Adds up all values in a numeric column.

 

Syntax:

SELECT SUM(marks) FROM Results;

 

Example: Total marks of all students.


3. AVG()

Purpose: Calculates the average of a numeric column.

 

Syntax:

SELECT AVG(marks) FROM Results;

 

Example: Find the average marks in a subject.


4. MIN()

Purpose: Finds the minimum (smallest) value in a column.

 

Syntax:

SELECT MIN(age) FROM Students;

 

Example: Youngest student’s age.


5. MAX()

Purpose: Finds the maximum (largest) value in a column.

 

Syntax:

SELECT MAX(salary) FROM Teachers;

 

Example: Highest salary among teachers.


Using Aggregate Functions with GROUP BY

You can combine aggregate functions with the GROUP BY clause to compute summaries per group (like per department, class, etc.).

 

Example:
SELECT department, AVG(salary)
FROM Employees
GROUP BY department;

 

This will show the average salary in each department.

0% Complete
WhatsApp Icon

Hi Instagram Fam!
Get a FREE Cheat Sheet on System Design.

Hi LinkedIn Fam!
Get a FREE Cheat Sheet on System Design

Loved Our YouTube Videos? Get a FREE Cheat Sheet on System Design.