I need to display employees that worked in the 'sales' department. I want to update the salary, when the employee is a manager, than add 30% salary and display the average salary of 'sales' department, but when the employee is a 'sales representative' then add 50% salary and display the average salary of 'sales'
Output example:
Manager John Russell 27817
Sales Jonathon Taylor 22517
Here's what I've done so far, any idea?
declare
i number := 0;
avg_sal int;
begin
for v_id in (select employee_id, first_name, manager_id, salary, job_id from employees
where department_id=(select department_id from departments where department_name='Sales'))
loop
update employees
set salary = case when (employee_id=(select distinct manager_id from employees)) then (salary+(salary*30/100)) when (job_id=(select job_id from jobs where job_title='Sales Representative')) then (salary+(salary*50/100)) end
where employee_id = v_id.employee_id;
i := i+1;
end loop;
loop
select avg(salary) from employees into avg_sal;
case when (employee_id=(select distinct manager_id from employees)) then dbms_output.put_line('Manager '||first_name||' '||avg_sal) when (job_id=(select job_id from jobs where job_title='Sales Representative')) then dbms_output.put_line('Sales '||first_name||' '||avg_sal) end
end;
/
The employee id, name, salary, manager, and job id are from the 'employees' table. While the job title like 'sales representative' is from the 'jobs' table. I need to use pl/sql control structure, record, and cursor. Thanks!