Download presentation
Presentation is loading. Please wait.
Published byAri Budiaman Modified over 5 years ago
1
Aggregate functions Objective- understand and able to use aggregate functions in select statement Aggregate functions are used to implement calculation based upon a particular column. These functions always return a single value.
2
Aggregate functions function purpose Sum()
To find the sum of values of an attribute Avg() To find the average of values of an attribute Max() To find the highest values of an attribute Min() To find the lowest value of an attribute Count(attribute) It gives the no. of non-null values in the particular attribute Count(*) It gives the no. of tuples (including null )
3
2) Select min(salary) from employee;
Aggregate function Ex: 1) Select max(salary) from employee; 2) Select min(salary) from employee; Output -1 TABLE - EMPLOYEE ID NAME SALARY place 1 ARUN 6000 Dubai 2 VARUN 8000 Sharjah 3 ALI 9000 Ajman 4 GEORGE 12000 5 MOHD dubai max(salary) 12000 Output -2 min(salary) 6000
4
Select sum(salary) from employee; Select count (*) from employee;
Aggregate function Ex: Select avg(salary) from employee; Select sum(salary) from employee; Select count (*) from employee; TABLE - EMPLOYEE ID NAME SALARY place 1 ARUN 6000 Dubai 2 VARUN 8000 Sharjah 3 ALI 9000 Ajman 4 GEORGE 12000 5 MOHD dubai Output -3 count(*) 5
5
Ex: Select max(salary) from employee where place = ‘Dubai’;
Aggregate function Ex: Select max(salary) from employee where place = ‘Dubai’; TABLE - EMPLOYEE ID NAME SALARY place 1 ARUN 6000 Dubai 2 VARUN 8000 Sharjah 3 ALI 9000 Ajman 4 GEORGE 12000 5 MOHD Output -1 max(salary) 8000
6
Ex: Select COUNT(*) from employee where place = ‘Dubai’;
Aggregate function Ex: Select COUNT(*) from employee where place = ‘Dubai’; TABLE - EMPLOYEE ID NAME SALARY place 1 ARUN 6000 Dubai 2 VARUN 8000 Sharjah 3 ALI 9000 Ajman 4 GEORGE 12000 5 MOHD Output -1 COUNT(*) 2
7
2) Select COUNT(MARK) from employee;
Aggregate function Ex:1) Select COUNT(*) from employee; 2) Select COUNT(MARK) from employee; Output -1 TABLE - EMPLOYEE COUNT(*) 5 ID NAME MARK 1 ARUN 50 2 VARUN 3 ALI 80 4 GEORGE 90 5 MOHD 78 Output -2 COUNT(mark) 4
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.