문제 URL : https://leetcode.com/problems/primary-department-for-each-employee/
Primary Department for Each Employee - LeetCode
Can you solve this real interview question? Primary Department for Each Employee - Table: Employee +---------------+---------+ | Column Name | Type | +---------------+---------+ | employee_id | int | | department_id | int | | primary_flag | varchar | +----
leetcode.com
문제 풀이: union을 이용한 문제입니다.
union all 과 혼동하시면안됩니다.
union 과 union all 의 차이점은
union은 중복된 데이터를 걸러주지만
union all을 그렇지 않다는것
소스코드 :
# Write your MySQL query statement below
select employee_id, department_id
from employee
where primary_flag= 'Y'
union
select employee_id, department_id
from employee
group by employee_id
having count(employee_id) =1
'LeetCode' 카테고리의 다른 글
[LeetCode] 300. Longest Increasing Subsequence (0) | 2023.09.12 |
---|---|
[LeetCode] 76. Minimum Window Substring (0) | 2023.09.12 |
[LeetCode] 185. Department Top Three Salaries (0) | 2023.09.06 |
[LeetCode] 239. Sliding Window Maximum (0) | 2023.09.06 |
[LeetCode] 240. Search a 2D Matrix II (0) | 2023.09.06 |