Exp 7-Implementation of Aggregate Functions in SQL
Exp 7-Implementation of Aggregate Functions in SQL
An aggregate function is a function that performs a calculation on a set of values, and returns a single
value. The most commonly used SQL aggregate functions are MIN( ), MAX( ), COUNT( ),SUM( )
and AVG( )
PRODUCT ( Draw table on Leftside)
ProductId ProductName Price
1 Book 18
2 Ink 19
3 Duster 10
4 Textbook 22
5 Bag 21
OUTPUT: 10
MAX( ) - returns the largest value within the selected column
Syntax:
SELECT MAX(column_name)
FROM table_name
WHERE condition;
Example:
SELECT MAX(Price) FROM Products;
OUTPUT: 22
COUNT( ) - returns the number of rows in a set
Syntax:
SELECT COUNT(column_name)
FROM table_name
WHERE condition;
Example:
SELECT COUNT(ProductId) FROM Products;
Output: 5
SUM( ) - returns the total sum of a numerical column
Syntax:
SELECT SUM(column_name)
FROM table_name
WHERE condition;
Example:
SELECT SUM(Price) FROM Products;
Output: 90
AVG( ) - returns the average value of a numerical column
Syntax:
SELECT AVG(column_name)
FROM table_name
WHERE condition;
Example:
SELECT AVG(Price) FROM Products;
Output: 18
RESULT:
Successfully implemented Aggregate functions in SQL and output verified.