File tree
Expand file treeCollapse file tree1 file changed
+71
-0
lines changed Expand file treeCollapse file tree1 file changed
+71
-0
lines changed Original file line number | Diff line number | Diff line change |
---|
|
| 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 | + |
1 | 72 | SELECT e.name , b.bonus
|
2 | 73 | FROM Employee e
|
3 | 74 | LEFT JOIN Bonus b ON e.empId=b.empId
|
|
You can’t perform that action at this time.
0 commit comments