commit daa86c00084ebec4cb2e9a1e76b2d854cf86eee5 parent 12fa59173082a6a9507e699ca4a9c16702fa1243 Author: AndrewLockVI <andrewlaack1@gmail.com> Date: Thu, 6 Jul 2023 20:26:41 -0500 Completed primary department using my sql Diffstat:
| A | primary-department-for-each-employee/primary-department.sql | | | 12 | ++++++++++++ |
1 file changed, 12 insertions(+), 0 deletions(-)
diff --git a/primary-department-for-each-employee/primary-department.sql b/primary-department-for-each-employee/primary-department.sql @@ -0,0 +1,12 @@ +--Given a table of employee locations return the +--primary location for each employee where the primary +--is set to 'N' if the employee only has one record + +SELECT DISTINCT Employee.employee_id, Employee.department_id +FROM Employee +WHERE Employee.primary_flag = 'Y' + OR ( + SELECT COUNT(*) + FROM Employee as E + WHERE E.employee_id = Employee.employee_id + ) = 1;