先筛选出salaries表中 to_date 为"9999-01-01" 然后再连接另外两个表 bonus计算: round(if(btype="1", salary * 0.1, if(btype="2", salary * 0.2, salary * 0.3)), 1) bonus round(..., 1) --- 保留一位小数
select emp_no, first_name, last_name, btype, salary,
round(if(btype="1", salary * 0.1, if(btype="2", salary * 0.2, salary * 0.3)), 1) bonus
from employees join emp_bonus using(emp_no)
join
(select * from salaries
where to_date = "9999-01-01") t using(emp_no);