Skip to content

Commit 18e54ca

Browse files
refactor 1148
1 parent 836b95c commit 18e54ca

File tree

1 file changed

+0
-43
lines changed

1 file changed

+0
-43
lines changed

database/_1148.sql

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1 @@
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
441
select distinct(author_id) as id from Views where author_id = viewer_id order by id asc;

0 commit comments

Comments
 (0)