题解 | #case...when... 条件判断列#

获取有奖金的员工相关信息。

https://www.nowcoder.com/practice/5cdbf1dcbe8d4c689020b6b2743820bf

select e.emp_no, e.first_name, e.last_name, eb.btype, s.salary,
case when eb.btype = 1 then s.salary * 0.1
when eb.btype = 2 then s.salary * 0.2
else s.salary * 0.3
end bonus
from employees e, emp_bonus eb, salaries s
where eb.emp_no = e.emp_no
and s.emp_no = e.emp_no
and s.to_date = '9999-01-01'

本题根据不同的选择对 salary 列的处理会有不同

case
	when ... then ...
    when ... then ...
    else ...
end

采用上述 case 条件选择语句进行处理即可。

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务