반응형
https://leetcode.com/problems/primary-department-for-each-employee/description/
group by와 where절을 사용해본 문제였습니다.
📕 풀이방법
📔 풀이과정
primary_flag = 'Y'거나 속한 부서가 1개인 employee_id, department_id를 선택해줍니다.
📕 Code
📔 ANSI SQL
SELECT employee_id, department_id
FROM employee e
WHERE primary_flag = 'Y'
OR (
employee_id in (
select employee_id from employee
group by employee_id
having count(employee_id) = 1
)
)
*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.
'SQL' 카테고리의 다른 글
(SQL, Python) - LeetCode (easy) 1890. The Latest Login in 2020 (1) | 2024.09.11 |
---|---|
(SQL) - LeetCode (easy) 1873. Calculate Special Bonus (0) | 2024.09.03 |
(SQL) - LeetCode (easy) 1757. Recyclable and Low Fat Products (0) | 2024.07.18 |
(SQL) - LeetCode (easy) 1741. Find Total Time Spent by Each Employee (0) | 2024.07.10 |
(SQL) - LeetCode (easy) 1729. Find Followers Count (0) | 2024.06.23 |