코딩테스트 SQL 코드카타 (Employee Bonus)

2024. 11. 20. 17:30·Daily 코드카타/SQL

문제

Employee Bonus - LeetCode

 

 

Write a solution to report the name and bonus amount of each employee
with a bonus less than 1000.

Return the result table in any order.

The result format is in the following example.

 

Example 1:

Input: 
Employee table:
+-------+--------+------------+--------+
| empId | name   | supervisor | salary |
+-------+--------+------------+--------+
| 3     | Brad   | null       | 4000   |
| 1     | John   | 3          | 1000   |
| 2     | Dan    | 3          | 2000   |
| 4     | Thomas | 3          | 4000   |
+-------+--------+------------+--------+
Bonus table:
+-------+-------+
| empId | bonus |
+-------+-------+
| 2     | 500   |
| 4     | 2000  |
+-------+-------+
Output: 
+------+-------+
| name | bonus |
+------+-------+
| Brad | null  |
| John | null  |
| Dan  | 500   |
+------+-------+

 

 


풀이

  1. 테이블의 결합
  2. 보너스를 1000초과하여 받은 인원 제외 하기
  3. 나머지 프린트
  4. 없다면 null

 


코드

 

bonus가 없을떄 null을 할당하기 위해 left join 사용.

 

bonus테이블의 값이  null 이거나 1000미만일때 표시

select e.name, b.bonus
from Employee e
left join Bonus b
on e.empID = b.empID
where b.empID is null or b.bonus < 1000

 

 


링크

LeetCode/0577-employee-bonus/0577-employee-bonus.sql at main · K-MarkLee/LeetCode

 

LeetCode/0577-employee-bonus/0577-employee-bonus.sql at main · K-MarkLee/LeetCode

Collection of LeetCode questions to ace the coding interview! - Created using [LeetHub](https://github.com/QasimWani/LeetHub) - K-MarkLee/LeetCode

github.com

 

 

 

저작자표시 비영리 변경금지 (새창열림)

'Daily 코드카타 > SQL' 카테고리의 다른 글

코딩테스트 SQL 코드카타 (Percentage of Users)  (1) 2024.11.27
코딩테스트 SQL 코드카타 (Project Employees)  (0) 2024.11.26
코딩테스트 SQL 코드카타 (Average Time of Process per Machine)  (0) 2024.11.19
코딩테스트 SQL 코드카나 (Rising Temperature)  (0) 2024.11.18
코딩테스트 SQL 코드카타 (Customer Who Visited without Any Transactions)  (0) 2024.11.17
'Daily 코드카타/SQL' 카테고리의 다른 글
  • 코딩테스트 SQL 코드카타 (Percentage of Users)
  • 코딩테스트 SQL 코드카타 (Project Employees)
  • 코딩테스트 SQL 코드카타 (Average Time of Process per Machine)
  • 코딩테스트 SQL 코드카나 (Rising Temperature)
코드 유랑자 승열
코드 유랑자 승열
코드 유랑자 승열의 프로그래밍 일지를 남기는 공간입니다.
  • 코드 유랑자 승열
    승열의 프로그래밍 시네마
    코드 유랑자 승열
  • 전체
    오늘
    어제
  • 링크

    • 깃허브 보러가기
    • 링크드인 보러가기
    • 인스타그램 보러가기
    • 카테고리 N
      • 코딩테스트 N
        • BaekJoon N
      • TIL and WIL
        • TIL
        • WIL
      • 주말스터디
      • 내일배움캠프
        • 사전캠프 강의 (SQL)
      • 용어정리
        • Python
        • Python-Library
        • Machine-Learning
        • Deep-Learning
        • AI 활용
        • LLM & RAG
        • Docker
        • Django
        • SQL
        • Java Script
        • etc
      • Daily 코드카타
        • SQL
        • Python 알고리즘
      • 임시저장
      • 보류
  • 태그

    RAG
    llm
    langchain
    word2vec
    django
    template
    오블완
    티스토리챌린지
    View
    vector db
  • 인기 글

  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.1
코드 유랑자 승열
코딩테스트 SQL 코드카타 (Employee Bonus)
상단으로

티스토리툴바