这么多题解,感觉没一个写对的,都是按照当前工资计算奖金,事实上应该按照奖金发放的日期时的工资作为奖金计算的基准,所以连接时应该加上 工资的 from_date 早于奖金receive date ; to_date 晚于奖金receive date,具体如下:

select

a.emp_no,

a.first_name,

a.last_name,

b.btype,

c.salary,

round(

(

case

when b.btype = 1 then c.salary * 0.1

when b.btype = 2 then c.salary * 0.2

else c.salary * 0.3

end

),

1

) as bonus

from

employees a

join emp_bonus b on a.emp_no = b.emp_no

join salaries c on b.emp_no = c.emp_no

and c.from_date <= b.recevied

and c.to_date >= b.recevied

order by

a.emp_no asc