Aggregate functions allow you to compute values from all or a subset of all of the data.
SELECT MAX(SALARY), MIN(SALARY), AVG(SALARY)
FROM EMPLOYEEThere are different types of aggregations we can use:
SUM(x): find the summation of all of the values of in the rowsMIN(x): find the smallest value of in the rowsMAX(x): find the largest value of in the rowsAVG(x): find the average value of in the rowsCOUNT(x): count the number of rows of in the data This will not includeNULLvalues.COUNT(DISTINCT x): count the number of rows of distinct occurrences of in the dataCOUNT(*): count the total number of rows
We may also use aggregations in sub-queries:
SELECT name
FROM EMPLOYEE
WHERE (
SELECT COUNT(*)
FROM DEPENDENT
WHERE ssn=ess
) >= 2This will find all the names of the employees who have two or more dependents.