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.
The most commonly used SQL aggregate functions are:
•MIN() - returns the smallest value within the selected column
•MAX() - returns the largest value within the selected column
•COUNT() - returns the number of rows in a set
•SUM() - returns the total sum of a numerical column
•AVG() - returns the average value of a numerical column
Dr. NGPASC
COIMBATORE | INDIA
, Aggregate functions
MIN() and MAX() Functions
The MIN() function returns the smallest value of the
selected column.
The MAX() function returns the largest value of the
selected column.
Example:
SELECT MIN(Price)FROM Products;
SELECT MIN(Price) AS SmallestPrice
FROM Products;
Dr. NGPASC
COIMBATORE | INDIA
, Aggregate functions
COUNT() Function
The COUNT() function returns the number of rows that matches a
specified criterion.
Example
SELECT COUNT(*) FROM Products;
Dr. NGPASC
COIMBATORE | INDIA
, Aggregate functions
SUM() Function
The SUM() function returns the total sum of a numeric column.
Example
SELECT SUM(Quantity) FROM OrderDetails;
Dr. NGPASC
COIMBATORE | INDIA
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.
The most commonly used SQL aggregate functions are:
•MIN() - returns the smallest value within the selected column
•MAX() - returns the largest value within the selected column
•COUNT() - returns the number of rows in a set
•SUM() - returns the total sum of a numerical column
•AVG() - returns the average value of a numerical column
Dr. NGPASC
COIMBATORE | INDIA
, Aggregate functions
MIN() and MAX() Functions
The MIN() function returns the smallest value of the
selected column.
The MAX() function returns the largest value of the
selected column.
Example:
SELECT MIN(Price)FROM Products;
SELECT MIN(Price) AS SmallestPrice
FROM Products;
Dr. NGPASC
COIMBATORE | INDIA
, Aggregate functions
COUNT() Function
The COUNT() function returns the number of rows that matches a
specified criterion.
Example
SELECT COUNT(*) FROM Products;
Dr. NGPASC
COIMBATORE | INDIA
, Aggregate functions
SUM() Function
The SUM() function returns the total sum of a numeric column.
Example
SELECT SUM(Quantity) FROM OrderDetails;
Dr. NGPASC
COIMBATORE | INDIA