Skip to content

Files

Latest commit

 Cannot retrieve latest commit at this time.

History

History
49 lines (35 loc) · 876 Bytes

125_primary_department_for_each_employee.md

File metadata and controls

49 lines (35 loc) · 876 Bytes

SQL Everyday #125

Primary Department for Each Employee

Site: LeetCode
Difficulty per Site: Easy

Problem

Write a solution to report all the employees with their primary department. For employees who belong to one department, report their only department.

Return the result table in any order. [Full Description]

Submitted Solution

-- Submitted Solution
SELECT
    employee_id
    ,department_id
FROM Employee
GROUP BY employee_id
HAVING COUNT(department_id) = 1
UNION
SELECT
    employee_id
    ,department_id
FROM Employee
WHERE primary_flag = 'Y'
;

Site Solution

-- LeetCode Solution 
-- Site solution essentially the same.

Notes

TODO

NB

UNION

Go to Index
Go to Overview