Growth ๐ŸŒณ/Practice ๐Ÿ’ป

[Leet code] 1075. Project Employees I

์ธ” 2023. 10. 6. 15:28

 

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

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


โœ”๋ฌธ์ œ

https://leetcode.com/problems/project-employees-i/description/

 

LeetCode - The World's Leading Online Programming Learning Platform

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

Table : Project

Table : Employee

Write an SQL query that reports the average experience years of all the employees for each project, rounded to 2 digits. Return the result table in any order.


โœ” ํ’€์ด

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

 

๊ฐ ํ”„๋กœ์ ํŠธ์— ์ฐธ์—ฌํ•œ ์ง์›๋“ค์˜ ํ‰๊ท  ๊ฒฝ๋ ฅ ์—ฐ์ˆ˜๋ฅผ ๋ฐ˜์˜ฌ๋ฆผํ•ด์„œ ์†Œ์ˆ˜์  2์ž๋ฆฌ๊นŒ์ง€ ์ถœ๋ ฅํ•ด์•ผํ•œ๋‹ค.

์กฐ์ธ ๊ธฐ์ค€์€ Project์™€ Empolyee ์˜ ๊ณตํ†ต์ปฌ๋Ÿผ employee_id๋กœ ํ•˜๋˜

๊ธฐ์ค€  ํ…Œ์ด๋ธ”์€ Project๋กœ ํ•ด์ค˜์•ผ ํ•œ๋‹ค.

Employee ํ…Œ์ด๋ธ” ๊ธฐ์ค€์œผ๋กœ ์กฐ์ธํ•˜๊ฒŒ ๋˜๋ฉด ํ”„๋กœ์ ํŠธ์— ๊ฒฝํ—˜์ด ์—†๋Š” ์ง์›์— ๋Œ€ํ•ด Project_id  null ๋ฐ์ดํ„ฐ๊ฐ€ ์ƒ์„ฑ๋œ๋‹ค.

ํ…Œ์ด๋ธ” ์กฐ์ธํ›„, project_id ๊ธฐ์ค€์œผ๋กœ ๊ทธ๋ฃนํ•‘ํ•ด์„œ ์ง์›๋“ค์˜ ๊ฒฝ๋ ฅ ์—ฐ์ˆ˜ ํ‰๊ท ๊ฐ’์„ ๊ตฌํ•ด์คฌ๋‹ค. 

SELECT project_id, 
	   ROUND(AVG(experience_years), 2) AS average_years
 FROM Project T1
 LEFT JOIN Employee T2
 ON T1.employee_id = T2.employee_id
 GROUP BY 1;

 

๐Ÿ™‹‍โ™€๏ธ ๋ฌธ์ œ ํ’€์ด์™€ mysql ์ฟผ๋ฆฌ ํšจ์œจ์„ฑ ๋†’์ด๊ธฐ ๋“ฑ ํฌ์ŠคํŒ…์— ๋Œ€ํ•œ ์˜๊ฒฌ ๋ฐ ๊ธฐ์ˆ  ์กฐ์–ธ ๋Œ“๊ธ€ ๋ชจ๋‘ ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค.

'Growth ๐ŸŒณ > Practice ๐Ÿ’ป' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Leet code] 1084. Sales Analysis III  (0) 2023.10.10
[Leet Code] 1068. Product Sales Analysis I  (1) 2023.10.07
[Leet code] 1934. Confirmation Rate  (1) 2023.10.05
[Leet code] 1393. Capital Gain/Loss  (1) 2023.10.04
[Leet code] 1204. Last Person to Fit in the Bus  (0) 2023.09.26