Я знаю, как выбрать среднюю зарплату для каждого отдела:
select departments.dept_name, 0.1* round(avg(salary),2) as raise
from employees
inner join departments using (dept_id)
group by dept_name;
But i have to do this raise for every employee with a result of:
The result i need to achieve
And I can't figure this out
The closest I can get is:
select surname, salary,
salary = (case when dept_id is null then 0 else round(avg(salary),2) end) as raise
from employees
group by dept_id, surname, salary
order by surname;
с результатом:
Результат моего кода sql