{ "data": { "question": { "questionId": "1258", "questionFrontendId": "1148", "categoryTitle": "Database", "boundTopicId": 33166, "title": "Article Views I", "titleSlug": "article-views-i", "content": "

Table: Views

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| article_id    | int     |\n| author_id     | int     |\n| viewer_id     | int     |\n| view_date     | date    |\n+---------------+---------+\nThere is no primary key for this table, it may have duplicate rows.\nEach row of this table indicates that some viewer viewed an article (written by some author) on some date. \nNote that equal author_id and viewer_id indicate the same person.\n
\n\n

 

\n\n

Write an SQL query to find all the authors that viewed at least one of their own articles.

\n\n

Return the result table sorted by id in ascending order.

\n\n

The query result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nViews table:\n+------------+-----------+-----------+------------+\n| article_id | author_id | viewer_id | view_date  |\n+------------+-----------+-----------+------------+\n| 1          | 3         | 5         | 2019-08-01 |\n| 1          | 3         | 6         | 2019-08-02 |\n| 2          | 7         | 7         | 2019-08-01 |\n| 2          | 7         | 6         | 2019-08-02 |\n| 4          | 7         | 1         | 2019-07-22 |\n| 3          | 4         | 4         | 2019-07-21 |\n| 3          | 4         | 4         | 2019-07-21 |\n+------------+-----------+-----------+------------+\nOutput: \n+------+\n| id   |\n+------+\n| 4    |\n| 7    |\n+------+\n
\n", "translatedTitle": "文章浏览 I", "translatedContent": "

Views 表:

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| article_id    | int     |\n| author_id     | int     |\n| viewer_id     | int     |\n| view_date     | date    |\n+---------------+---------+\n此表无主键,因此可能会存在重复行。\n此表的每一行都表示某人在某天浏览了某位作者的某篇文章。\n请注意,同一人的 author_id 和 viewer_id 是相同的。\n
\n\n

 

\n\n

请编写一条 SQL 查询以找出所有浏览过自己文章的作者,结果按照 id 升序排列。

\n\n

查询结果的格式如下所示:

\n\n
\nViews 表:\n+------------+-----------+-----------+------------+\n| article_id | author_id | viewer_id | view_date  |\n+------------+-----------+-----------+------------+\n| 1          | 3         | 5         | 2019-08-01 |\n| 1          | 3         | 6         | 2019-08-02 |\n| 2          | 7         | 7         | 2019-08-01 |\n| 2          | 7         | 6         | 2019-08-02 |\n| 4          | 7         | 1         | 2019-07-22 |\n| 3          | 4         | 4         | 2019-07-21 |\n| 3          | 4         | 4         | 2019-07-21 |\n+------------+-----------+-----------+------------+\n\n结果表:\n+------+\n| id   |\n+------+\n| 4    |\n| 7    |\n+------+\n
\n", "isPaidOnly": false, "difficulty": "Easy", "likes": 15, "dislikes": 0, "isLiked": null, "similarQuestions": "[]", "contributors": [], "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"ruby\": false, \"bash\": false, \"swift\": false, \"golang\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"kotlin\": false, \"rust\": false, \"php\": false, \"typescript\": false, \"racket\": false, \"erlang\": false, \"elixir\": false}", "topicTags": [ { "name": "Database", "slug": "database", "translatedName": "数据库", "__typename": "TopicTagNode" } ], "companyTagStats": null, "codeSnippets": [ { "lang": "MySQL", "langSlug": "mysql", "code": "# Write your MySQL query statement below", "__typename": "CodeSnippetNode" }, { "lang": "MS SQL Server", "langSlug": "mssql", "code": "/* Write your T-SQL query statement below */", "__typename": "CodeSnippetNode" }, { "lang": "Oracle", "langSlug": "oraclesql", "code": "/* Write your PL/SQL query statement below */", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"10.1K\", \"totalSubmission\": \"14.1K\", \"totalAcceptedRaw\": 10066, \"totalSubmissionRaw\": 14124, \"acRate\": \"71.3%\"}", "hints": [], "solution": null, "status": null, "sampleTestCase": "{\"headers\":{\"Views\":[\"article_id\",\"author_id\",\"viewer_id\",\"view_date\"]},\"rows\":{\"Views\":[[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\"]]}}", "metaData": "{\n \"mysql\": [\n \"Create table If Not Exists Views (article_id int, author_id int, viewer_id int, view_date date)\"\n ],\n \"mssql\": [\n \"Create table Views (article_id int, author_id int, viewer_id int, view_date date)\"\n ],\n \"oraclesql\": [\n \"Create table Views (article_id int, author_id int, viewer_id int, view_date date)\",\n \"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"\n ],\n \"database\": true\n}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [ "Create table If Not Exists Views (article_id int, author_id int, viewer_id int, view_date date)", "Truncate table Views", "insert into Views (article_id, author_id, viewer_id, view_date) values ('1', '3', '5', '2019-08-01')", "insert into Views (article_id, author_id, viewer_id, view_date) values ('1', '3', '6', '2019-08-02')", "insert into Views (article_id, author_id, viewer_id, view_date) values ('2', '7', '7', '2019-08-01')", "insert into Views (article_id, author_id, viewer_id, view_date) values ('2', '7', '6', '2019-08-02')", "insert into Views (article_id, author_id, viewer_id, view_date) values ('4', '7', '1', '2019-07-22')", "insert into Views (article_id, author_id, viewer_id, view_date) values ('3', '4', '4', '2019-07-21')", "insert into Views (article_id, author_id, viewer_id, view_date) values ('3', '4', '4', '2019-07-21')" ], "enableRunCode": true, "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"]}", "book": null, "isSubscribed": false, "isDailyQuestion": false, "dailyRecordStatus": null, "editorType": "CKEDITOR", "ugcQuestionId": null, "style": "LEETCODE", "exampleTestcases": "{\"headers\":{\"Views\":[\"article_id\",\"author_id\",\"viewer_id\",\"view_date\"]},\"rows\":{\"Views\":[[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\"]]}}", "__typename": "QuestionNode" } } }