Last updated on January 21st, 2025 at 09:54 pm
Here, we see the Article Views I LeetCode Solution. This Leetcode problem is solved using MySQL and Pandas.
List of all LeetCode Solution
Level of Question
Easy
Article Views I LeetCode Solution
Table of Contents
1. Problem Statement
Column Name | Type |
article_id | int |
author_id | int |
viewer_id | int |
view_date | date |
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_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 |
2. Code Implementation in Different Languages
2.1 Article Views I MySQL
select distinct author_id as id from Views where author_id = viewer_id order by author_id;