-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1148-ArticleViews1.sql
More file actions
31 lines (28 loc) · 1005 Bytes
/
1148-ArticleViews1.sql
File metadata and controls
31 lines (28 loc) · 1005 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
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.
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 |
+------+
*/
SELECT distinct(author_id) AS id
FROM Views
WHERE author_id = viewer_id
ORDER BY author_id ASC