Databases Laboratory 3: Marin Iuliana
Databases Laboratory 3: Marin Iuliana
Laboratory 3
Marin Iuliana
Lab Objectives
Group functions work across many rows to produce one result per
group.
The WHERE clause restricts rows before inclusion in a group
calculation.
Groups are restricted using HAVING.
Display the minimum, maximum, sum, and average salary for each job
type.
SELECT job_id, ROUND(MAX(salary),0) "Maximum",
ROUND(MIN(salary),0) "Minimum",
ROUND(SUM(salary),0) "Sum",
ROUND(AVG(salary),0) "Average"
FROM employees
GROUP BY job_id;
Reporting Aggregated Data Using the Group
Functions
Create a matrix query to display the job, the salary for that job
based on the department number, and the total salary for that
job, for departments 20, 50, 80, and 90, giving each column
an appropriate heading.
Create a report for HR that displays the last name and salary of
every employee who reports to King.
SELECT last_name, salary
FROM employees
WHERE manager_id = (SELECT employee_id
FROM employees
WHERE last_name = 'King');
Create a report that displays a list of all employees whose salary
is more than the salary of any employee from department 60.
SELECT last_name FROM employees
WHERE salary > ANY (SELECT salary
FROM employees
WHERE department_id=60);
Activities