
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

















Aggregate functions are functions that take a collection of values as input and return a single value.
Behavior of Aggregate Functions:
Operates - on a single column Return - a single value. Used only in the SELECT list and in the HAVING clause.
Types of SQL Aggregate Functions
Each function eliminates NULL values and operates on Non- null values.
Returns: The sum of the values in a specified column.
Example: Find the total/sum of the Managers salary
Query: SELECT SUM( salary) AS sum_salary FROM Staff WHERE Staff.position = ‘Manager’;
Result: sum_salary
Returns: The average of the values in a specified column.
Example: Find the average of the Project Managers salary.
Query: SELECT AVG( DISTINCT salary) AS avg_salary FROM Staff WHERE Staff.position = ‘Project Manager’;
Result: avg_salary 10500.00 // Error in Result // avg_salary = 11000. // What is wrong?
sno fname lname salary position
SL100 John White 30000.00 Manager
SL101 Susan Brand 24000.00 Manager
SL102 David Ford 12000.00 Project Manager
SL103 Ann Beech 12000.00 Project Manager
SL104 Mary Howe 9000.00 Project ManagerDocsity.com
Returns: MIN() returns the smallest value of a column. MAX() returns the largest value of a column.
Example: Find the minimum and maximum staff salary.
Query: SELECT MIN( salary) AS min_salary, MAX (salary) AS max_salary FROM Staff;
Result: min_salary max_salary 9000.00 30000.
sno fname lname salary position
SL100 John White 30000.00 Manager
SL101 Susan Brand 24000.00 Manager
Example: Find the total number of Managers and the sum of there salary.
Query: SELECT COUNT( sno) AS sno_count , SUM(salary) AS sum_salary From Staff WHERE Staff.position = ‘Manager’;
COUNT SUM Docsity.com
sno_count sum_salary
2 54000.
Input: There is no input to this function.
Returns: It counts all the rows of a table , regardless of whether Nulls or the duplicate occur.
Example: How many Project Manager salary is more than
Query: SELECT COUNT(*) AS Count_Salary FROM Staff WHERE Staff.position = ‘Project Manager’ AND Staff.salary > 9000.
Count_ Salary
2
sno bno fname lname salary position
SL100 B3 John White 30000.00 Manager
SL101 B5 Susan Brand 24000.00 Manager
SL102 B3 David Ford 12000.00 Project Manager
SL103 B5 Ann Beech 12000.00 Project Manager
SL104 B7 Mary Howe 9000.00 Project Manager