Skip to content

Commit fdf8bfb

Browse files
add 1378
1 parent 0fdc39d commit fdf8bfb

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,7 @@ _If you like this project, please leave me a star._ ★
923923

924924
| # | Title | Solutions | Video | Difficulty | Tag
925925
|-----|----------------|---------------|---------------|---------------|-------------
926+
|1378|[Replace Employee ID With The Unique Identifier](https://leetcode.com/problems/replace-employee-id-with-the-unique-identifier/)|[Solution](../master/database/_1378.sql) || Easy |
926927
|1369|[Get the Second Most Recent Activity](https://leetcode.com/problems/get-the-second-most-recent-activity/)|[Solution](../master/database/_1369.sql) || Hard |
927928
|1364|[Number of Trusted Contacts of a Customer](https://leetcode.com/problems/number-of-trusted-contacts-of-a-customer/)|[Solution](../master/database/_1364.sql) || Medium |
928929
|1355|[Activity Participants](https://leetcode.com/problems/activity-participants/)|[Solution](../master/database/_1355.sql) || Medium |

database/_1378.sql

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
--1378. Replace Employee ID With The Unique Identifier
2+
--
3+
--Table: Employees
4+
--
5+
--+---------------+---------+
6+
--| Column Name | Type |
7+
--+---------------+---------+
8+
--| id | int |
9+
--| name | varchar |
10+
--+---------------+---------+
11+
--id is the primary key for this table.
12+
--Each row of this table contains the id and the name of an employee in a company.
13+
--
14+
--
15+
--Table: EmployeeUNI
16+
--
17+
--+---------------+---------+
18+
--| Column Name | Type |
19+
--+---------------+---------+
20+
--| id | int |
21+
--| unique_id | int |
22+
--+---------------+---------+
23+
--(id, unique_id) is the primary key for this table.
24+
--Each row of this table contains the id and the corresponding unique id of an employee in the company.
25+
--
26+
--
27+
--Write an SQL query to show the unique ID of each user, If a user doesn't have a unique ID replace just show null.
28+
--
29+
--Return the result table in any order.
30+
--
31+
--The query result format is in the following example:
32+
--
33+
--Employees table:
34+
--+----+----------+
35+
--| id | name |
36+
--+----+----------+
37+
--| 1 | Alice |
38+
--| 7 | Bob |
39+
--| 11 | Meir |
40+
--| 90 | Winston |
41+
--| 3 | Jonathan |
42+
--+----+----------+
43+
--
44+
--EmployeeUNI table:
45+
--+----+-----------+
46+
--| id | unique_id |
47+
--+----+-----------+
48+
--| 3 | 1 |
49+
--| 11 | 2 |
50+
--| 90 | 3 |
51+
--+----+-----------+
52+
--
53+
--EmployeeUNI table:
54+
--+-----------+----------+
55+
--| unique_id | name |
56+
--+-----------+----------+
57+
--| null | Alice |
58+
--| null | Bob |
59+
--| 2 | Meir |
60+
--| 3 | Winston |
61+
--| 1 | Jonathan |
62+
--+-----------+----------+
63+
--
64+
--Alice and Bob don't have a unique ID, We will show null instead.
65+
--The unique ID of Meir is 2.
66+
--The unique ID of Winston is 3.
67+
--The unique ID of Jonathan is 1.
68+
--
69+
--# Write your MySQL query statement below
70+
71+
select uni.unique_id, emp.name from Employees emp
72+
left join
73+
EmployeeUNI uni
74+
on emp.id = uni.id

0 commit comments

Comments
 (0)