♟️ 알고리즘/Leetcode

[MySQL][Leet Code] 1378. Replace Employee ID With The Unique Identifier (Easy)

Jerry_K 2025. 2. 17. 19:57

https://leetcode.com/problems/replace-employee-id-with-the-unique-identifier/description/?envType=study-plan-v2&envId=top-sql-50https://leetcode.com/problems/article-views-i/?envType=study-plan-v2&envId=top-sql-50


🗒️SQL 코드 풀이 1

SELECT unique_id , name
FROM Employees e LEFT JOIN EmployeeUNI eu ON e.id = eu.id

 

1. 간단한 JOIN 문제로 먼저 가져올 테이블 Employee를 선택한다.

 

2. 이후 EmployeeUNI와 JOIN을 하는데, id를 기준으로 해준다.

 

 

📌 문제 코멘트 

문법을 잘 몰라서 풀지 못했다 .

JOIN 문제에 익숙해져보자. 

 


📚문제

https://leetcode.com/problems/find-customer-referee/description/?envType=study-plan-v2&envId=top-sql-50https://leetcode.com/problems/article-views-i/?envType=study-plan-v2&envId=top-sql-50


🗒️SQL 코드 풀이 1

SELECT DISTINCT author_id AS id 
FROM Views
WHERE author_id = viewer_id
ORDER BY id

 

1. 간단한 SQL 문제이다.  먼저 가져올 테이블 Views를 선택한다.

 

2. 이후 author_id와 viewer_id가 같은 조건을 걸어준다 .

 

3. 선택 할 컬럼은 author_id이로 Alias는 id로 해준다. 그리고 중복 출력 제거를 위해 DISTINCT를 했다.

 

4. 이후 ORDER BY 문법을 사용하면 오름차순으로 정렬된다. ( Default가 오름차순)

 

 

 

📌 문제 코멘트 

역시 어려운 문제가 아니지만, MySQL과 좀 더 친해지기 위해 포스팅을 해본다.


📚문제