Dbms 3rd
Dbms 3rd
An aggregate function is a function that performs a calculation on a set of values, and returns a single value.
Aggregate functions are often used with 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.
The most commonly used SQL aggregate functions are:
1) MIN() - return the smallest value within the selected column.
2) MAX() - returns the largest value within the selected column
3) COUNT() - returns the number of rows in a set.
4) SUM() - returns the total sum of a numerical column
5) AVG() - returns the average value of a numerical column.
The MAX() function returns the largest value of the selected column.
• MIN Example Syntax:
SELECT MIN(column_name)
FROM table_name
WHERE condition;
• MAX Example
Syntax:
SELECT MAX(column_name)
FROM table_name
WHERE condition;
Set Column Name
When you use MIN() or MAX(), the returned column will not have a descriptive name. To give the column a descriptive name,
use the AS keyword:
Example
Syntax
SELECT COUNT(column_name)
FROM table_name
WHERE condition;