You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Each row of this table indicates the employee ID, employee name, and salary.
13
+
14
+
15
+
Required Query:
16
+
17
+
1) Calculate the bonus of each employee. The bonus of an employee is 100% of their salary if the ID of the employee is an odd number and the employee name does not start with the character 'M'. The bonus of an employee is 0 otherwise.
18
+
19
+
2) Return the result table ordered by employee_id.
20
+
21
+
22
+
SQL Schema:
23
+
24
+
Create table If Not Exists Employees (employee_id int, name varchar(30), salary int)
25
+
Truncate table Employees
26
+
insert into Employees (employee_id, name, salary) values ('2', 'Meir', '3000')
27
+
insert into Employees (employee_id, name, salary) values ('3', 'Michael', '3800')
28
+
insert into Employees (employee_id, name, salary) values ('7', 'Addilyn', '7400')
29
+
insert into Employees (employee_id, name, salary) values ('8', 'Juan', '6100')
30
+
insert into Employees (employee_id, name, salary) values ('9', 'Kannon', '7700')
31
+
32
+
Example:
33
+
34
+
Input:
35
+
Employees table:
36
+
+-------------+---------+--------+
37
+
| employee_id | name | salary |
38
+
+-------------+---------+--------+
39
+
| 2 | Meir | 3000 |
40
+
| 3 | Michael | 3800 |
41
+
| 7 | Addilyn | 7400 |
42
+
| 8 | Juan | 6100 |
43
+
| 9 | Kannon | 7700 |
44
+
+-------------+---------+--------+
45
+
Output:
46
+
+-------------+-------+
47
+
| employee_id | bonus |
48
+
+-------------+-------+
49
+
| 2 | 0 |
50
+
| 3 | 0 |
51
+
| 7 | 7400 |
52
+
| 8 | 0 |
53
+
| 9 | 7700 |
54
+
+-------------+-------+
55
+
*/
56
+
57
+
-- Solution:
58
+
SELECT employee_id,
59
+
(
60
+
CASE
61
+
WHEN employee_id % 2!=0AND name NOT LIKE'M%' THEN salary
0 commit comments