leetcode

Leetcode submissions
git clone git://git.laack.co/leetcode.git
Log | Files | Refs | README

primary-department.sql (388B)


      1 --Given a table of employee locations return the
      2 --primary location for each employee where the primary
      3 --is set to 'N' if the employee only has one record
      4 
      5 SELECT DISTINCT Employee.employee_id, Employee.department_id
      6 FROM Employee
      7 WHERE Employee.primary_flag = 'Y' 
      8    OR (
      9        SELECT COUNT(*) 
     10        FROM Employee as E 
     11        WHERE E.employee_id = Employee.employee_id
     12      ) = 1;