Skip to content

Latest commit

 

History

History

1873-Calculate-Special-Bonus

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
Source : https://leetcode.com/problems/calculate-special-bonus/
Author : liuyubobobo
Time   : 2022-04-15

Using UNION

(
    SELECT employee_id, salary as bonus 
    FROM Employees
    WHERE employee_id % 2 = 1 AND name NOT LIKE 'M%'
)
UNION
(
    SELECT employee_id, 0 as bonus 
    FROM Employees
    WHERE employee_id % 2 = 0 OR name LIKE 'M%'
)
ORDER BY employee_id

Using IF

SELECT employee_id, 
IF(employee_id % 2 = 1 AND name NOT LIKE 'M%' , salary, 0) as bonus 
FROM Employees
ORDER BY employee_id

Using CASE

SELECT employee_id, 
CASE 
    WHEN employee_id % 2 = 1 AND name NOT LIKE 'M%' THEN salary
    ELSE 0
END as bonus 
FROM Employees
ORDER BY employee_id