Employee Bonus Problem


Description

LeetCode Problem 577.

Select all employee’s name and bonus whose bonus is < 1000.

Table: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 is the primary key column for this table.

Table: Bonus

1
2
3
4
5
6
7
+-------+-------+
| empId | bonus |
+-------+-------+
| 2     | 500   |
| 4     | 2000  |
+-------+-------+
empId is the primary key column for this table.

Example ouput:

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


MySQL Solution

1
2
3
4
5
select name, bonus
from Employee e
left join Bonus b
on e.empId = b.empId 
where b.bonus < 1000 or b.bonus is null




Related Posts

Find Median Given Frequency Of Numbers Problem

LeetCode 571. Write a query to find the median of...

Find Cumulative Salary Of An Employee Problem

LeetCode 579. Write a SQL to get the cumulative sum...

Get Highest Answer Rate Question Problem

LeetCode 578. Write a sql query to identify the question...

Winning Candidate Problem

LeetCode 574. Write a sql to find the name of...

Managers With At Least 5 Direct Reports Problem

LeetCode 570. Given the Employee table, write a SQL query...

Employee Bonus Problem

LeetCode 577. Select all employee’s name and bonus whose bonus...