577. 员工奖金

题目

选出所有 bonus < 1000 的员工的 name 及其 bonus。

Employee 表单

1
2
3
4
5
6
7
8
9
+-------+--------+-----------+--------+
| empId | name | supervisor| salary |
+-------+--------+-----------+--------+
| 1 | John | 3 | 1000 |
| 2 | Dan | 3 | 2000 |
| 3 | Brad | null | 4000 |
| 4 | Thomas | 3 | 4000 |
+-------+--------+-----------+--------+
empId 是这张表单的主关键字

Bonus 表单

1
2
3
4
5
6
7
+-------+-------+
| empId | bonus |
+-------+-------+
| 2 | 500 |
| 4 | 2000 |
+-------+-------+
empId 是这张表单的主关键字

示例1:

1
2
3
4
5
6
7
+-------+-------+
| name | bonus |
+-------+-------+
| John | null |
| Dan | 500 |
| Brad | null |
+-------+-------+

解法

解法一:

SQL

1
select name, bonus from Bonus right join Employee on Bonus.empId = Employee.empId where bonus < 1000 or bonus is null;
0%