select c.*, d.salary, case when c.btype=1 then round(d.salary*0.1,1) when c.btype=2 then round(d.salary*0.2,1) else round(d.salary*0.3,1) end bonus from ( select a.emp_no,a.first_name,a.last_name,b.btype from employees a inner join emp_bonus b on a.emp_no=b.emp_no )c inner join ( select * from salaries where to_date='9999-01-01' ) d on c.emp_no=d.emp_no order by c.emp_no