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과 좀 더 친해지기 위해 포스팅을 해본다.
📚문제
'♟️ 알고리즘 > Leetcode' 카테고리의 다른 글
[MySQL][Leet Code] 1280. Students and Examinations (Easy) (0) | 2025.02.17 |
---|---|
[MySQL][Leet Code] 197. Rising Temperature (Easy) (0) | 2025.02.17 |
[MySQL][Leet Code] 1581. Customer Who Visited but Did Not Make Any Transactions (Easy) (0) | 2025.02.17 |
[MySQL][Leet Code] 1148. Article Views I (Easy) (0) | 2025.02.17 |
[MySQL][Leet Code] 584. Find Customer Referee (Easy) (0) | 2025.02.11 |