diff --git a/README.md b/README.md index 43f9975..9d1184c 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ Useful for preparing for technical interviews and improving your SQL skills. - [1741. Find Total Time Spent by Each Employee](./leetcode/easy/1741.%20Find%20Total%20Time%20Spent%20by%20Each%20Employee.sql) - [1789. Primary Department for Each Employee](./leetcode/easy/1789.%20Primary%20Department%20for%20Each%20Employee.sql) - [1795. Rearrange Products Table](./leetcode/easy/1795.%20Rearrange%20Products%20Table.sql) + - [1873. Calculate Special Bonus](./leetcode/easy/1873.%20Calculate%20Special%20Bonus.sql) - [1890. The Latest Login in 2020](./leetcode/easy/1890.%20The%20Latest%20Login%20in%202020.sql) - [1965. Employees With Missing Information](./leetcode/easy/1965.%20Employees%20With%20Missing%20Information.sql) - [1978. Employees Whose Manager Left the Company](./leetcode/easy/1978.%20Employees%20Whose%20Manager%20Left%20the%20Company.sql) diff --git a/leetcode/easy/1873. Calculate Special Bonus.sql b/leetcode/easy/1873. Calculate Special Bonus.sql new file mode 100644 index 0000000..8ad39db --- /dev/null +++ b/leetcode/easy/1873. Calculate Special Bonus.sql @@ -0,0 +1,31 @@ +/* +Question 1873. Calculate Special Bonus +Link: https://leetcode.com/problems/calculate-special-bonus/description/?envType=problem-list-v2&envId=database + +Table: Employees + ++-------------+---------+ +| Column Name | Type | ++-------------+---------+ +| employee_id | int | +| name | varchar | +| salary | int | ++-------------+---------+ +employee_id is the primary key (column with unique values) for this table. +Each row of this table indicates the employee ID, employee name, and salary. + + +Write a solution to 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's name does not start with the character 'M'. The bonus of an employee is 0 otherwise. + +Return the result table ordered by employee_id. +*/ + +SELECT + employee_id, + (CASE + WHEN employee_id % 2 = 0 OR LEFT(name, 1) = 'M' + THEN 0 + ELSE salary + END) AS bonus +FROM Employees +ORDER BY employee_id ASC