Aggregate Functions (with Examples) in DBMS

DBMS | Aggregate Functions: In this tutorial, we will learn about the different types of aggregate functions with their usage, syntax, and examples in DBMS. By Anushree Goswami Last updated : May 27, 2023

What are Aggregate Functions in DBMS?

In a database management system (like SQL), the aggregate functions are used to perform the calculation based on multiple rows and return a single value according to the given query. All these aggregate functions are used with a SELECT statement.

Types of Aggregate Functions

The various aggregate functions are: AVG(), COUNT(), SUM(), MAX(), and MIN().

1. AVG() Function

The AVG() function is used to find the average of the values from a numeric column.

Example:

Write an SQL query to find the average age from the citizen table.

SELECT AVG(age) FROM citizen;

2. COUNT() Function

The COUNT() function is used to find the total number of values/rows from the table by excluding the NULL values.

Example:

Write an SQL query to count the number of rows having an age greater than or equal to 21.

SELECT COUNT(*) FROM citizen WHERE age >= 21;

3. SUM() Function

The SUM() function is used to find the sum of all values in the given numeric column.

Example:

Write an SQL query to find the sum of the pension given to the citizen.

SELECT SUM(pension) FROM citizen;

4. MAX() Function

The MAX() function is used to find the maximum value from the given numeric column.

Example:

Write an SQL query to find the maximum age of a citizen/ to find the age of the oldest citizen.

SELECT MAX(age) FROM citizen;

5. MIN() Function

The MIN() function is used to find the minimum value from the given numeric column.

Example:

Write an SQL query to find the minimum age of a citizen/ to find the age of the youngest citizen.

SELECT MIN(age) FROM citizen;


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.