inblog logo
|
stupefyee
    SQL문제풀기

    [SQL 문제 풀이] Article Views I (기사 보기 I)

    Stupefyee's avatar
    Stupefyee
    May 14, 2025
    [SQL 문제 풀이] Article Views I (기사 보기 I)
    Contents
    내가 작성한 쿼리
    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 | +---------------+---------+ There is no primary key (column with unique values) for this table, the table may have duplicate rows. Each row of this table indicates that some viewer viewed an article (written by some author) on some date. Note that equal author_id and viewer_id indicate the same person.   Write a solution to find all the authors that viewed at least one of their own articles. Return the result table sorted by id in ascending order. The result format is in the following example.   Example 1: Input: Views table: +------------+-----------+-----------+------------+ | article_id | author_id | viewer_id | view_date | +------------+-----------+-----------+------------+ | 1 | 3 | 5 | 2019-08-01 | | 1 | 3 | 6 | 2019-08-02 | | 2 | 7 | 7 | 2019-08-01 | | 2 | 7 | 6 | 2019-08-02 | | 4 | 7 | 1 | 2019-07-22 | | 3 | 4 | 4 | 2019-07-21 | | 3 | 4 | 4 | 2019-07-21 | +------------+-----------+-----------+------------+ Output: +------+ | id | +------+ | 4 | | 7 | +------+
    Article Views I - LeetCode
    https://leetcode.com/problems/article-views-i/description/
    Article Views I - LeetCode
    notion image
    자신의 기사 중 적어도 하나를 본 모든 저자를 찾기 위한 해결책을 작성하세요. ID별로 정렬된 결과 테이블을 오름차순으로 반환합니다.
     

    내가 작성한 쿼리

    MySQL, Oracle

    SELECT DISTINCT author_id id FROM Views WHERE author_id = viewer_id ORDER BY id;
    Share article
    Contents
    내가 작성한 쿼리

    stupefyee

    RSS·Powered by Inblog