노력에는 지름길이 없으니까요

(★) LeetCode - 1789. Primary Department for Each Employee 본문

SQL/LeetCode

(★) LeetCode - 1789. Primary Department for Each Employee

데건 2024. 8. 12. 11:19
728x90

 

해결일 언어 레벨 테스트명
20240812 SQL easy  1789. Primary Department for Each Employee

 

링크 : https://leetcode.com/problems/primary-department-for-each-employee/

 

 

테스트 케이스에 말도 안되는 게 하나 껴있었는데... (22번!!!)

토론 에리어에서는 결국 잘못된 데이터에 대해서도 대처할 수 있는 코드를 짜는 것도 능력이다. <로 다들 귀결하고 있기에

내 실력이 아직 멀었구나 따위를 느끼는 중이다

 

 

다음에 다시 풀어봐야지...👊

 


 

 

베스트 코드

# Write your MySQL query statement below

(SELECT
    employee_id,
    department_id
FROM Employee
GROUP BY 1
HAVING COUNT(DISTINCT department_id) = 1
)
UNION ALL
(SELECT
    employee_id
    ,department_id 
FROM Employee 
WHERE primary_flag = 'Y'
)

 

 

728x90
반응형