File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,74 @@
1+
-- Problem:
2+
3+
/*
4+
Table: Employee
5+
6+
+-------------+---------+
7+
| Column Name | Type |
8+
+-------------+---------+
9+
| empId | int |
10+
| name | varchar |
11+
| supervisor | int |
12+
| salary | int |
13+
+-------------+---------+
14+
empId is the column with unique values for this table.
15+
Each row of this table indicates the name and the ID of an employee in addition to their salary and the id of their manager.
16+
17+
18+
Table: Bonus
19+
20+
+-------------+------+
21+
| Column Name | Type |
22+
+-------------+------+
23+
| empId | int |
24+
| bonus | int |
25+
+-------------+------+
26+
empId is the column of unique values for this table.
27+
empId is a foreign key (reference column) to empId from the Employee table.
28+
Each row of this table contains the id of an employee and their respective bonus.
29+
30+
31+
Write a solution to report the name and bonus amount of each employee with a bonus less than 1000.
32+
33+
Return the result table in any order.
34+
35+
The result format is in the following example.
36+
37+
38+
39+
Example 1:
40+
41+
Input:
42+
Employee table:
43+
+-------+--------+------------+--------+
44+
| empId | name | supervisor | salary |
45+
+-------+--------+------------+--------+
46+
| 3 | Brad | null | 4000 |
47+
| 1 | John | 3 | 1000 |
48+
| 2 | Dan | 3 | 2000 |
49+
| 4 | Thomas | 3 | 4000 |
50+
+-------+--------+------------+--------+
51+
Bonus table:
52+
+-------+-------+
53+
| empId | bonus |
54+
+-------+-------+
55+
| 2 | 500 |
56+
| 4 | 2000 |
57+
+-------+-------+
58+
Output:
59+
+------+-------+
60+
| name | bonus |
61+
+------+-------+
62+
| Brad | null |
63+
| John | null |
64+
| Dan | 500 |
65+
+------+-------+
66+
*/
67+
68+
-------------------------------------------------------------------------------
69+
70+
-- Solution:
71+
172
SELECT e.name , b.bonus
273
FROM Employee e
374
LEFT JOIN Bonus b ON e.empId=b.empId

0 commit comments

Comments
 (0)