From c183106fc6c2480564789c13cdba199d69158232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Antonio=20Chac=C3=B3n=20Guti=C3=A9rrez?= <138903866+joseantoniochacon@users.noreply.github.com> Date: Tue, 11 Jun 2024 14:37:05 -0600 Subject: [PATCH] Create README - LeetHub --- .../README.md | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 1789-primary-department-for-each-employee/README.md diff --git a/1789-primary-department-for-each-employee/README.md b/1789-primary-department-for-each-employee/README.md new file mode 100644 index 0000000..6d2720a --- /dev/null +++ b/1789-primary-department-for-each-employee/README.md @@ -0,0 +1,57 @@ +

1789. Primary Department for Each Employee

Easy


SQL Schema

Table: Employee

+ +
+---------------+---------+
+| Column Name   |  Type   |
++---------------+---------+
+| employee_id   | int     |
+| department_id | int     |
+| primary_flag  | varchar |
++---------------+---------+
+(employee_id, department_id) is the primary key (combination of columns with unique values) for this table.
+employee_id is the id of the employee.
+department_id is the id of the department to which the employee belongs.
+primary_flag is an ENUM (category) of type ('Y', 'N'). If the flag is 'Y', the department is the primary department for the employee. If the flag is 'N', the department is not the primary.
+
+ +

 

+ +

Employees can belong to multiple departments. When the employee joins other departments, they need to decide which department is their primary department. Note that when an employee belongs to only one department, their primary column is 'N'.

+ +

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.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
Input: 
+Employee table:
++-------------+---------------+--------------+
+| employee_id | department_id | primary_flag |
++-------------+---------------+--------------+
+| 1           | 1             | N            |
+| 2           | 1             | Y            |
+| 2           | 2             | N            |
+| 3           | 3             | N            |
+| 4           | 2             | N            |
+| 4           | 3             | Y            |
+| 4           | 4             | N            |
++-------------+---------------+--------------+
+Output: 
++-------------+---------------+
+| employee_id | department_id |
++-------------+---------------+
+| 1           | 1             |
+| 2           | 1             |
+| 3           | 3             |
+| 4           | 3             |
++-------------+---------------+
+Explanation: 
+- The Primary department for employee 1 is 1.
+- The Primary department for employee 2 is 1.
+- The Primary department for employee 3 is 3.
+- The Primary department for employee 4 is 3.
+
+
\ No newline at end of file