문제
입력 코드
1.
SELECT employee_id, department_id
FROM Employee
GROUP BY employee_id
HAVING COUNT(employee_id) = 1
UNION
SELECT employee_id, department_id
FROM Employee
WHERE primary_flag = 'Y'
2.
SELECT DISTINCT employee_id, department_id
FROM Employee
WHERE employee_id IN (
SELECT employee_id
FROM Employee
GROUP BY employee_id
HAVING COUNT(*) = 1
)
OR primary_flag = 'Y'
ORDER BY employee_id;
코드 설명
#SELECT #GROUP BY #HAVING #COUNT #UNION #DISTINCT #ORDER BY
문제 출처
'SQL' 카테고리의 다른 글
#107. [LeetCode / MySQL] 180. Consecutive Numbers (0) | 2023.10.03 |
---|---|
#106. [LeetCode / MySQL] 610. Triangle Judgement (0) | 2023.10.02 |
#104. [LeetCode / MySQL] 1731. The Number of Employees Which Report to Each Employee (0) | 2023.09.30 |
#103. [LeetCode / MySQL] 1045. Customers Who Bought All Products (0) | 2023.09.29 |
#101. [LeetCode / MySQL] 1729. Find Followers Count (0) | 2023.09.27 |