577.编写解决方案,报告每个奖金 少于 1000
的员工的姓名和奖金数额。
建表插入数据:
Create table If Not Exists Employee (empId int, name varchar(255), supervisor int, salary int)
Create table If Not Exists Bonus (empId int, bonus int)
Truncate table Employee
insert into Employee (empId, name, supervisor, salary) values ('3', 'Brad', 'None', '4000')
insert into Employee (empId, name, supervisor, salary) values ('1', 'John', '3', '1000')
insert into Employee (empId, name, supervisor, salary) values ('2', 'Dan', '3', '2000')
insert into Employee (empId, name, supervisor, salary) values ('4', 'Thomas', '3', '4000')
Truncate table Bonus
insert into Bonus (empId, bonus) values ('2', '500')
insert into Bonus (empId, bonus) values ('4', '2000')
思路分析:
将两个表进行左连接,过滤的条件是奖金是空,或者奖金小于1000的员工姓名和奖金金额
画图分析:
代码实现:
select name,bonus
from employee e left join bonus b
on e.empId=b.empId
where bonus is null or bonus<1000;