♟️ 알고리즘/Leetcode

[MySQL][Leet Code] 1148. Article Views I (Easy)

Jerry_K 2025. 2. 17. 18:13

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과 좀 더 친해지기 위해 포스팅을 해본다.


📚문제