👉https://leetcode.com/problems/calculate-special-bonus/description/?envType=study-plan&id=sql-i
🤔 문제 분석
1) Write an SQL query to calculate the bonus of each employee.
2) 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.
3) Return the result table ordered by employee_id.
💡 풀이
SELECT employee_id, IF(MOD(employee_id, 2) = 1 AND name NOT LIKE "M%", salary, 0) AS bonus
FROM Employees
ORDER BY employee_id
'코딩테스트 > 리트코드 SQL' 카테고리의 다른 글
[리트코드/SQL] 7. Delete Duplicate Emails (196) (0) | 2022.12.05 |
---|---|
[리트코드/SQL] 6. Swap Salary (627) (0) | 2022.12.05 |
4. Customers Who Never Order (183) (0) | 2022.12.01 |
3. Find Customer Referee (584) (0) | 2022.12.01 |
2. Recyclable and Low Fat Products (1757) (0) | 2022.12.01 |
댓글