File tree Expand file tree Collapse file tree 1 file changed +0
-43
lines changed
Expand file tree Collapse file tree 1 file changed +0
-43
lines changed Original file line number Diff line number Diff line change 1- -- 1148. Article Views I
2- --
3- -- Table: Views
4- --
5- -- +---------------+---------+
6- -- | Column Name | Type |
7- -- +---------------+---------+
8- -- | article_id | int |
9- -- | author_id | int |
10- -- | viewer_id | int |
11- -- | view_date | date |
12- -- +---------------+---------+
13- -- There is no primary key for this table, it may have duplicate rows.
14- -- Each row of this table indicates that some viewer viewed an article (written by some author) on some date.
15- -- Note that equal author_id and viewer_id indicate the same person.
16- --
17- --
18- -- Write an SQL query to find all the authors that viewed at least one of their own articles, sorted in ascending order by their id.
19- --
20- -- The query result format is in the following example:
21- --
22- -- Views table:
23- -- +------------+-----------+-----------+------------+
24- -- | article_id | author_id | viewer_id | view_date |
25- -- +------------+-----------+-----------+------------+
26- -- | 1 | 3 | 5 | 2019-08-01 |
27- -- | 1 | 3 | 6 | 2019-08-02 |
28- -- | 2 | 7 | 7 | 2019-08-01 |
29- -- | 2 | 7 | 6 | 2019-08-02 |
30- -- | 4 | 7 | 1 | 2019-07-22 |
31- -- | 3 | 4 | 4 | 2019-07-21 |
32- -- | 3 | 4 | 4 | 2019-07-21 |
33- -- +------------+-----------+-----------+------------+
34- --
35- -- Result table:
36- -- +------+
37- -- | id |
38- -- +------+
39- -- | 4 |
40- -- | 7 |
41- -- +------+
42-
43- -- # Write your MySQL query statement below
441select distinct (author_id) as id from Views where author_id = viewer_id order by id asc ;
You can’t perform that action at this time.
0 commit comments