Sei sulla pagina 1di 11

Doomshell Academy of Advance Computing

Agreegate Function

Agreegate Function
 Aggregate functions are functions that take a collection of values as
input and return a single value.

 In a table agree gate function will be apply on all the columns value
and return a single value.

 Used only in the SELECT clause.


Ty p e s

Types of Agreegate function :-


 SUM
 AVG
 MIN
 MAX
 COUNT
 FIRST
 LAST
Records

Empsal Table
sid Name Salary position

1 John 18000 Manager

2 David 20000 Developer

3 Sushil 25000 Manager

4 Madhu 32000 Manager

5 Sneha 21000 Developer

6 Shekhar 42000 Manager


Sum()function

 SUM( ):-
It is use to add the value.

Syntax:- SELECT SUM(column_name) FROM table_name;

NOTE:-
SELECT:- The select statement is use to select from a database.

Example: Find the total/sum of the salary

Query:- SELECT SUM( salary ) AS sum_salary FROM empsal;

Result Total_salary
158000
Mvagi (n) tfaubnlcetsi o n
A

 AVG( ):-
It is use to find average value.

Syntax:- SELECT AVG(column_name) FROM table_name;

Example: Find the avg of the salary

Query:- SELECT AVG( salary ) AS avg_salary FROM empsal;

avg_salary
Result
26333.333
S uoabui nt tat(ba) lbfelusensc t i o n
M
C

 COUNT( ):-
It is use to count the values.

Syntax:- SELECT COUNT(*) FROM table_name where condition;

NOTE:-
where:- The where caluse is used to extract only those records that
fulfill a specified condition.

Example: - Count the number of managers.

Query:- SELECT COUNT( * ) FROM empsal where position=”Manager”;

count_Manager
Result
3
FMi rasi tn( )t af bu lnecst i o n

 FIRST( ):-
The FIRST() function returns the first value.

Syntax:- SELECT FIRST(column_name) FROM table_name;

Example: Find the first value of the selected area.

Query:- SELECT FIRST( name) FROM empsal;

first_name
Result
john
LMaas itn( ) t faubnl ec st i o n

 LAST( ):-
The LAST( ) function returns the first value.

Syntax:- SELECT LAST(column_name) FROM table_name;

Example: Find the last value of the selected area.

Query:- SELECT LAST( name) FROM empsal;

last_name
Result
Shekhar
M a xi n( ) t faubnl ec st i o n

 MAX( ):-
The MAX() function returns the maximum value.

Syntax:- SELECT MAX(column_name) FROM table_name;

Example: Find the largest value of the salary.

Query:- SELECT MAX( salary) FROM empsal;

Max_salary
Result
42000
M iani n( ) tfaubnl cetsi o n

 MIN( ):-
The MIN() function returns the minimum value.

Syntax:- SELECT MIN(column_name) FROM table_name;

Example: Find the minimum value of the salary.

Query:- SELECT MIN(salary) FROM empsal;

min_salary
Result
18000

Potrebbero piacerti anche