返回介绍

solution / 1100-1199 / 1149.Article Views II / README_EN

发布于 2024-06-17 01:03:23 字数 2047 浏览 0 评论 0 收藏 0

1149. Article Views II

中文文档

Description

Table: Views

+---------------+---------+
| Column Name   | Type  |
+---------------+---------+
| article_id  | int   |
| author_id   | int   |
| viewer_id   | int   |
| view_date   | date  |
+---------------+---------+
This 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 people who viewed more than one article on the same date.

Return the result table sorted by id in ascending order.

The result format is in the following example.

 

Example 1:

Input: 
Views table:
+------------+-----------+-----------+------------+
| article_id | author_id | viewer_id | view_date  |
+------------+-----------+-----------+------------+
| 1      | 3     | 5     | 2019-08-01 |
| 3      | 4     | 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   |
+------+
| 5  |
| 6  |
+------+

Solutions

Solution 1

# Write your MySQL query statement below
SELECT DISTINCT viewer_id AS id
FROM Views
GROUP BY viewer_id, view_date
HAVING COUNT(DISTINCT article_id) > 1
ORDER BY 1;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文