8000 Create Leetcode 1873. Calculate Special Bonus · priyesh0453/SQL-LeetCode@40b3242 · GitHub
[go: up one dir, main page]

Skip to content

Commit 40b3242

Browse files
committed
Create Leetcode 1873. Calculate Special Bonus
1 parent 71e07df commit 40b3242

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
Table: Employees
3+
4+
+-------------+---------+
5+
| Column Name | Type |
6+
+-------------+---------+
7+
| employee_id | int |
8+
| name | varchar |
9+
| salary | int |
10+
+-------------+---------+
11+
employee_id is the primary key for this table.
12+
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 != 0 AND name NOT LIKE 'M%' THEN salary
62+
ELSE 0
63+
END
64+
) AS bonus
65+
FROM Employees
66+
ORDER BY employee_id ASC

0 commit comments

Comments
 (0)
0