Article Views I LeetCode Solution

This Leetcode problem Article Views I LeetCode Solution is done in SQL.

List of all LeetCode Solution

Article Views I LeetCode Solution

Article Views I LeetCode Solution

Problem Statement

Column NameType
article_id int
author_idint
viewer_idint
view_datedate
Table: Views

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:

article_id author_id viewer_idview_date
1352019-08-01
1362019-08-02
2772019-08-01
2762019-08-02
4712019-07-22
3442019-07-21
3442019-07-21
Views table:

Output:

id
4
7

Article Views I LeetCode Solution MySQL

select 
  distinct author_id as id 
from 
  Views 
where 
  author_id = viewer_id 
order by 
  author_id;Code language: SQL (Structured Query Language) (sql)
Scroll to Top