











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!












Aggregation is an operation that computes a single
value from all the values of an attribute.
SQL provides five functions that apply to an attribute
of a relation and produce some aggregation of that column.
SUM(SALARY) MAX(SALARY) MIN(SALARY) AVG(SALARY)
317,000 55,000 25,000 39,
DNAME='Research';
Query: For each department, retrieve the department
number, the number of employees in the department and their average salary.
This query can be expressed in SQL as follows:
The result of this query will be:
DNO COUNT(*) AVG(SALARY)
5 4 36,
4 3 39,
1 1 55,
The result of an SQL query involving aggregate functions, GROUP BY and HAVING can be computed as follows:
1. Evaluate the relation R implied by the FROM and WHERE clauses. R is the Cartesian product of the relations specified in the FROM clause, to which the selection of the WHERE clause is applied.
2. Group the tuples of R according to the attributes in the GROUP BY clause.
3. Filter out the tuples of R not satisfying the condition of the HAVING clause to compute a new relation R.
4. Apply to R the projections and aggregations specified in the SELECT clause to compute the final result. Docsity.com