Schema:
departments (department_id, department_name, manager_id, location_id) , employees (employee_id, first_name, last_name, email, phone_number, hire_date, job_id, salary, commission_pct, department_id)
testo dell'esercizio :
mostrare {first_name, last_name, salary} di tutti gli impiegati che percepiscono uno stipendio maggiore della media dei salari e lavorano in un dipartimento il cui nome contiene la parola “IT”;
il mio svolgimento:
select first_name, last_name, salary
from employees
where salary>(select avg (salary)
from employees
where department_id=any (select department_id
from departments
where department_name like '%IT%'))
la soluzione del prof:
SELECT first_name, last_name, salary
FROM employees AS e1
WHERE salary > (
SELECT AVG(salary)
FROM employees
) AND department_id IN (
SELECT department_id
FROM departments
WHERE department_name LIKE '%IT%')