SQL

[leetCode] #1148 (쿼리실행순서)

빛날희- 2023. 7. 19. 22:05

문제 - Article Views I

https://leetcode.com/problems/article-views-i/

 

Article Views I - LeetCode

Can you solve this real interview question? Article Views I - Table: Views +---------------+---------+ | Column Name | Type | +---------------+---------+ | article_id | int | | author_id | int | | viewer_id | int | | view_date | date | +---------------+---

leetcode.com

Find all the authors that viewed at least one of their own articles.

Return the result table sorted by id in ascending order.

 

 

작성 답안

select distinct v.author_id as id
from views as v
where v.viewer_id = v.author_id
order by v.author_id asc

 

리뷰

- 쿼리 실행 순서

    from -> where -> groupby -> having -> order by -> select

    (groupby 이후 조건문은 having 으로 설정)