题目
选出所有 bonus < 1000 的员工的 name 及其 bonus。
Employee
表单
Bonus
表单
输出示例:
解题思路
1.题目要求查询所有 bonus < 1000 的员工的 name 及其 bonus。我们先将 Employee 表和 bonus 进行左连接 连接条件是 e.empId = a.empId
2.然后在所连接的表中查询 a.Bonus < 1000 or a.Bonus is null ,返回 e.name, a.Bonus 即可
代码实现
select e.name, a.Bonus
from Employee as e left join Bonus as a on e.empId = a.empId
where a.Bonus < 1000 or a.Bonus is null
测试结果
扫描二维码关注公众号,回复:
15602557 查看本文章