Growth ๐ŸŒณ/Practice ๐Ÿ’ป

[LeetCode] 577. Employee Bonus

์ธ” 2023. 5. 10. 14:42

 

๐Ÿ“ข ๋ณธ ํฌ์ŠคํŒ…์— ํ™œ์šฉ๋˜๋Š” ๊ธฐ๋ณธ ๋ฌธ์ œ ๋ฐ ์ž๋ฃŒ ์ถœ์ฒ˜๋Š”

       ๋ฆฌํŠธ์ฝ”๋“œ Problems, https://leetcode.com/problemset/all/์ž„์„ ๋ฐํž™๋‹ˆ๋‹ค.


โ–  ๋ฌธ์ œ

https://leetcode.com/problems/employee-bonus/

 

Employee Bonus - LeetCode

Can you solve this real interview question? Employee Bonus - Table: Employee +-------------+---------+ | Column Name | Type | +-------------+---------+ | empId | int | | name | varchar | | supervisor | int | | salary | int | +-------------+---------+ empId

leetcode.com

Table : Employee

 

Table : Bonus

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

Return the result table in any order.

The query result format is in the following example.


โ–  ํ’€์ด

  ๋ฌธ์ œ ์š”๊ตฌ์‚ฌํ•ญ  

 

๊ทผ๋กœ์ž ์ด๋ฆ„๊ณผ ๋ณด๋„ˆ์Šค๋ฅผ ์ถœ๋ ฅํ•˜๋Š”๋ฐ ๋ณด๋„ˆ์Šค๊ฐ€ 1000 ๋ฏธ๋งŒ์ธ

์ถœ๋ ฅ(์ •๋ ฌ) ์ˆœ์„œ๋Š” ์ƒ๊ด€ ์—†์Œ.

์ถœ๋ ฅ ์˜ˆ์‹œ ๊ฒฐ๊ณผ๋ฅผ ๋ณด๋ฉด, bonus๊ฐ€ ์—†๋Š” ๊ทผ๋กœ์ž๋“ค์€ null๋กœ ์ถœ๋ ฅ๋˜์–ด์•ผ ํ•œ๋‹ค.*

๋”ฐ๋ผ์„œ

์กฐ๊ฑดโ‘  *Employee ํ…Œ์ด๋ธ” ๊ธฐ์ค€์œผ๋กœ Bonus ํ…Œ์ด๋ธ”์„ left join  ํ•ด์ค€๋‹ค.

์กฐ๊ฑดโ‘ก ๋ณด๋„ˆ์Šค๊ฐ€ 1000 ๋ฏธ๋งŒ์„ ์กฐ๊ฑด์œผ๋กœ ์„ค์ •ํ•œ๋‹ค.

            (์ค‘์š”ํ•œ ์  : ๋ณด๋„ˆ์Šค๊ฐ€ ์—†๋Š” ์ง์›๋„ 1000 ๋ฏธ๋งŒ์— ํ•ด๋‹นํ•˜๋ฏ€๋กœ bonus์ปฌ๋Ÿผ์ด null๊ฐ’์ธ ๊ทผ๋กœ์ž๋„ ์กฐ๊ฑด์— 

              OR ์กฐ๊ฑด์œผ๋กœ ๋„ฃ์–ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.)

SELECT T1.name, T2.bonus
 FROM Employee T1
 LEFT JOIN Bonus T2
 ON T1.empId = T2.empId
 WHERE T2.bonus < 1000 OR T2.bonus is null