saurus2
Saurus2
saurus2
전체 방문자
오늘
어제
  • 분류 전체보기
    • 개발
      • AJAX
    • ML Ops
    • Profile
    • 음식점
    • 배낭여행
    • 컴퓨터공학
      • 알고리즘 공부
      • C++
      • Sever 스터디
      • Java spring
      • 알고리즘 _ 문제해결
      • 딥러닝
      • Java 정리
      • Python
      • LeetCode 1000
      • Machine Learning Study
      • Sign language Detection Pro..
      • LeetCode Solutions
    • 비콘
    • 데일리 리포트
    • 유학일기
      • 영어 공부
      • Daily
    • AI Master Degree
      • Data Mining
      • AI and Data engineering
      • Math Foundations for Decisi..
      • Natural Language Processing

블로그 메뉴

  • 홈
  • 태그
  • 미디어로그
  • 위치로그
  • 방명록

공지사항

인기 글

태그

  • 릿코드
  • 알고리즘문제해결
  • Python
  • 취준
  • 온라인저지
  • LeetCode
  • BFS
  • 개발자
  • c++
  • 문제해결능력
  • 파이썬
  • 딕셔너리
  • 알고리즘
  • 리트코드
  • 백준
  • 개발자 취업준비
  • 딥러닝
  • DFS
  • two pointer
  • 취업준비

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
saurus2

Saurus2

컴퓨터공학/LeetCode 1000

[LeetCode] 1873. Calculate Special Bonus

2022. 11. 23. 10:23

1873. Calculate Special Bonus

Easy

SQL Schema

Table: Employees

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| employee_id | int     |
| name        | varchar |
| salary      | int     |
+-------------+---------+
employee_id is the primary key for this table.
Each row of this table indicates the employee ID, employee name, and salary.

 

Write an SQL query 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 name does not start with the character 'M'. The bonus of an employee is 0 otherwise.

Return the result table ordered by employee_id.

The query result format is in the following example.

 

Example 1:

Input: 
Employees table:
+-------------+---------+--------+
| employee_id | name    | salary |
+-------------+---------+--------+
| 2           | Meir    | 3000   |
| 3           | Michael | 3800   |
| 7           | Addilyn | 7400   |
| 8           | Juan    | 6100   |
| 9           | Kannon  | 7700   |
+-------------+---------+--------+
Output: 
+-------------+-------+
| employee_id | bonus |
+-------------+-------+
| 2           | 0     |
| 3           | 0     |
| 7           | 7400  |
| 8           | 0     |
| 9           | 7700  |
+-------------+-------+
Explanation: 
The employees with IDs 2 and 8 get 0 bonus because they have an even employee_id.
The employee with ID 3 gets 0 bonus because their name starts with 'M'.
The rest of the employees get a 100% bonus.

문제 풀이

  • employees 테이블에서 employee_id가 홀수가 아니고 이름이 M으로 시작하지 않는 사람은 보너스를 샐러리 만큼 준다.
  • employee_id가 짝수이거나 이름이 M으로 시작하면 보너스를 0만 준다.
  • 위 조건으로 테이블을 만들고 employee_id로 정렬해야한다. 

소스 코드

# Write your MySQL query statement below
select employee_id, salary as bonus
from Employees
where employee_id % 2 <> 0 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
저작자표시

'컴퓨터공학 > LeetCode 1000' 카테고리의 다른 글

[LeetCode] 2225. Find Players With Zero or One Losses  (0) 2022.11.29
[LeetCode] 627. Swap Salary  (0) 2022.11.23
[LeetCode] 796. Rotate String  (0) 2022.11.23
[LeetCode] 487. Max Consecutive Ones II  (0) 2022.11.23
[LeetCode] 140. Word Break II  (0) 2022.11.14
    '컴퓨터공학/LeetCode 1000' 카테고리의 다른 글
    • [LeetCode] 2225. Find Players With Zero or One Losses
    • [LeetCode] 627. Swap Salary
    • [LeetCode] 796. Rotate String
    • [LeetCode] 487. Max Consecutive Ones II
    saurus2
    saurus2
    Simple is Best

    티스토리툴바