Zadanie 15.

Z każdego departamentu wybierz pracownika, który zarabia najmniej.

Schemat: HR, Tabela: Employees, Kolumny: department_id, first_name, last_name, salary, Wynik: 12 rows

s15

 

 

 

Rozwiązanie

SELECT department_id, first_name, last_name, salary
FROM employees
WHERE (department_id, salary) in (
SELECT department_id, MIN(salary)
FROM employees
GROUP BY department_id)

ORDER BY department_id;

[collapse]