Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Aggregate Functions

• Aggregate is used to group multiple rows together as input to


provide a single value output.
• An Aggregate Function performs a calculation on a set of values
and returns a single value.
• Aggregate Functions are used with group by statements to
group the output of the query by multiple columns.
• Basic SQL provides five Aggregate Functions:

1. avg():
Returns average value of a specified column.
Used only for numeric datatype.

2. min():
Returns lowest value of a specified column.

3. max():
Returns highest value of a specified column.

4. sum():
Returns addition of all the values in a specified column.

5. count():
counts the number of rows in a specified column.

Fundamentals Of SQL
Consider the following table for Examples:
StudentID Name DeptID Marks
1 Alice 101 55
2 Bob 102 34
3 Rachel 103 67
4 Carry 104 45
5 Skye 105 64

Examples:

1. select avg(Marks)
from Student;

Output: avg(Marks)
53

2. select min(Marks)
from Student;

Output: min(Marks)
34

3. select max(Marks)
from Student;

Output: max(Marks)
67

Fundamentals Of SQL
4. select sum(Marks)
from Student;

Output: sum(Marks)
265

5. select count(Marks) (Returns total number of


from Student; rows in the column Marks.)
OR

select count(*) (Returns total number of


from Student rows in the entire table.)

Output:
count(Marks)
5

Fundamentals Of SQL

You might also like