Professional Documents
Culture Documents
AGGREGATE(GROUP) FUNCTIONS:
Multiple row functions perform operations on multiple values and return result as single value.
These functions are called aggregate functions.
The aggregate functions are:
1) Max()
2) Min()
3) Avg()
4) Sum()
5) Count()
Consider the following “EMPL” table.
1) max()
MAX() function is used to find the highest value of any column or any expression based on a column.
Eg: To display maximum salary of an employee from empl relation.
2) Min()
MIN() function is used to find the lowest value of any column or an expression based on a column.
Eg: To display minimum salary of an employee from empl relation.
INFORMATICS PRACTICES (065) - XII BY G SIVA PRASAD (PGT)
3) Avg()
AVG () function is used to find the average value of any column or an expression based on a column.
Eg: To display average salary of all employees from empl relation.
4) Sum()
SUM() function is used to find the total value of any column or an expression based on a column.
Eg (1): To display total salary of all employees from empl relation.
Eg (2): To display total net salary (salary+commission) of all employees from empl relation.
5) Count()
COUNT() function is used to count the number of values in a column. COUNT() takes one argument
which can be any column name, an expression based on a column, or an asterisk (*).
When the argument is a column name or an expression based on a column, COUNT() returns the
number of non-NULL values in that column.
If the argument is a *, then COUNT() counts the total number of rows satisfying the condition, if any,
in the table.
Eg (1): To display the number of employees who are getting commission.
INFORMATICS PRACTICES (065) - XII BY G SIVA PRASAD (PGT)
Eg (2): To display the number of employees who in empl relation.
Note: None of the aggregate functions takes NULL into consideration. NULL is simply ignored by all the
aggregate functions.
Eg (1): To display the no.of employees in each department along with department number from empl
relation.
Eg (2): To display the total salary of all employees in each department along with department number
from empl relation.
Eg (3): To display the minimum, maximum, and average salary of all employees in each department
along with department number from empl relation.
INFORMATICS PRACTICES (065) - XII BY G SIVA PRASAD (PGT)
(vi) SELECT A.SenderName, B.RecName FROM Sender A, Recipient b WHERE SenderID=B.SenderID AND
Eg (4): To display the no.of employees in each department along with department number from empl
relation except whose commission is null.
HAVING Clause:
The HAVING clause places conditions on groups. But, WHERE clause that places conditions on
individual rows.
WHERE clause conditions cannot include aggregate functions, but HAVING clause conditions can
do so.
Eg (1): to display the job and their no.of employees where employees count is less than 3.
Eg (2): To display the no.of employees in each department along with department number from empl
relation except whose commission is null and department total salary must greater than 5000.