Aggregate Functions in DBMS
Aggregate Functions
Aggregate functions are often used with the GROUP BY clause of the SELECT statement.
The GROUP BY clause splits the result-set into groups of values and the aggregate function
can be used to return a single value for each group.
MIN()
The MIN() function returns the smallest value within the selected column.
Syntax- SELECT MAX(column_name)
FROM table_name;
example - SELECT MIN(Price)
FROM Products;
MAX()
The MAX() function returns the largest value of the selected column.
Syntax- SELECT MAX(column_name)
FROM table_name;
example - SELECT MAX(Price)
FROM Products;
COUNT()
The COUNT() function returns the number of rows that matches a specified criterion.
Syntax- SELECT COUNT(column_name)
FROM table_name;
Example- SELECT COUNT(*)
FROM Products;
SUM()
The SUM() function returns the total sum of a numeric column.
Syntax- SELECT SUM(column_name)
FROM table_name;
Example - SELECT SUM(Quantity)
FROM OrderDetails;
AVG()
The AVG() function returns the average value of a numeric column.
Syntax- SELECT AVG(column_name)
FROM table_name;
Example- SELECT AVG(Price)
FROM Products;