LeetCode MySQL 1149. 文章浏览 II
发布日期:2021-07-01 03:30:00 浏览次数:2 分类:技术文章

本文共 1381 字,大约阅读时间需要 4 分钟。

文章目录

1. 题目

Table: Views

+---------------+---------+| Column Name   | Type    |+---------------+---------+| article_id    | int     || author_id     | int     || viewer_id     | int     || view_date     | date    |+---------------+---------+

此表无主键,因此可能会存在重复行。

此表的每一行都表示某人在某天浏览了某位作者的某篇文章。
请注意,同一人的 author_id 和 viewer_id 是相同的。

编写一条 SQL 查询来找出在同一天阅读至少两篇文章的人,结果按照 id 升序排序。

查询结果的格式如下:

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 |+------------+-----------+-----------+------------+Result table:+------+| id   |+------+| 5    || 6    |+------+

来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/article-views-ii

著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

2. 解题

# Write your MySQL query statement belowselect distinct viewer_id idfrom Viewsgroup by view_date, viewer_idhaving count(distinct article_id) >= 2order by viewer_id

我的CSDN

长按或扫码关注我的公众号(Michael阿明),一起加油、一起学习进步!

Michael阿明

转载地址:https://michael.blog.csdn.net/article/details/107568637 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:LeetCode MySQL 1164. 指定日期的产品价格 *
下一篇:LeetCode MySQL 1107. 每日新用户统计

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2024年05月06日 16时14分03秒