This document discusses SQL aggregation functions such as COUNT, SUM, AVG, MAX, and MIN. It provides examples of using each function to aggregate data from a sample table containing employee names and page counts. The COUNT function returns the number of rows, SUM adds values, AVG calculates the average, MAX returns the largest value, and MIN returns the smallest value. Syntax examples are given for each function applied to the sample data.
2. PREPARED BY
MS.G.ABIRAMI – III - B.SC - INFORMATION TECHNOLOGY
UNDER THE GUIDANCE OF
MRS.P.ANUSHA M.SC(IT).,M.PHIL.,D.P.T.T.,(PH.D).,
ASSISTANT PROFESSOR,
DEPARTMENT OF INFORMATION TECHNOLOGY,
BON SECOURS COLLEGE FOR WOMEN,
THANJAVUR.
3. SQL AGGREGATE FUNCTION
SQL aggregation function is used to perform the calculation
on multiple rows of a single column of a table. It returns a
single value.
It is also used to summarize the data.
This function ignore the null values except the count
function .
4.
5. TYPES OF SQL AGGREGATION FUNCTION
Count ( ) : Returns the numbers of rows
Sum ( ) : Returns the sum
Avg ( ) : Returns the average value
Max ( ) : Returns the smallest value
Min ( ) : Returns the largest value
6. COUNT FUNCTION
Count function is used to count the number of rows in database table
.It can work on both numeric and non-numeric data types.
Count function uses the count (*) that returns the count of all the
rows in a specific table. Count (*) considers duplicate and null .
This function does not count the null value .
Table name :Employee
7. EXAMPLE :TABLE
NAME DATE PAGES
RAMU 22022-01-12 34
GEETHA 22022-01-12 74
SEETHA 22022-01-12 64
RAM 22022-01-12 94
SUKRIA 22022-01-12 64
8. SYNTAX OF COUNT
Syntax: select count(Pages) from employee;
Count (pages)
5
1 row in set
Syntax: select count (name) from employee;
Count(name)
5
1 row in set
9. SUM FUNCTION
• Sum() function is an aggregate function that calculates the sum of
all or distinct values in an expression .
SYNTAX: SELECT SUM (PAGES) FROM EMPLOYEE;
SUM(PAGES)
330
1 ROW IN A SET
10. AVERAGE FUNCTION
• The avg function is used to calculate the average value of the
numeric type. Average function returns the average of all non-null
values.
syntax: select avg (pages)from employee;
avg(pages)
66.0000
1row in set
11. MAX FUNCTION
• Max function is used to find the maximum value of certain column.
This function determines the largest value of all selected values of
columns.
Syntax: select max (pages) from employee;
Max(pages)
94
1 row in set
12. MIN FUNCTION
• The Min function is used to find the minimum value of certain
column. This function determines the smallest value of all selected
values of a column.
syntax: Select min(pages)from employee ;
Min(pages)
34
1 row in set