• LeetCode 1113.报告的记录


    数据准备

    Create table If Not Exists Actions (user_id int, post_id int, action_date date, action ENUM('view', 'like', 'reaction', 'comment', 'report', 'share'), extra varchar(10));
    Truncate table Actions;
    insert into Actions (user_id, post_id, action_date, action, extra) values ('1', '1', '2019-07-01', 'view', 'None');
    insert into Actions (user_id, post_id, action_date, action, extra) values ('1', '1', '2019-07-01', 'like', 'None');
    insert into Actions (user_id, post_id, action_date, action, extra) values ('1', '1', '2019-07-01', 'share', 'None');
    insert into Actions (user_id, post_id, action_date, action, extra) values ('2', '4', '2019-07-04', 'view', 'None');
    insert into Actions (user_id, post_id, action_date, action, extra) values ('2', '4', '2019-07-04', 'report', 'spam');
    insert into Actions (user_id, post_id, action_date, action, extra) values ('3', '4', '2019-07-04', 'view', 'None');
    insert into Actions (user_id, post_id, action_date, action, extra) values ('3', '4', '2019-07-04', 'report', 'spam');
    insert into Actions (user_id, post_id, action_date, action, extra) values ('4', '3', '2019-07-02', 'view', 'None');
    insert into Actions (user_id, post_id, action_date, action, extra) values ('4', '3', '2019-07-02', 'report', 'spam');
    insert into Actions (user_id, post_id, action_date, action, extra) values ('5', '2', '2019-07-04', 'view', 'None');
    insert into Actions (user_id, post_id, action_date, action, extra) values ('5', '2', '2019-07-04', 'report', 'racism');
    insert into Actions (user_id, post_id, action_date, action, extra) values ('5', '5', '2019-07-04', 'view', 'None');
    insert into Actions (user_id, post_id, action_date, action, extra) values ('5', '5', '2019-07-04', 'report', 'racism');
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    需求

    编写一条SQL,查询每种报告理由(report reason)在昨天的不同报告数量(post_id)。假设今天是2019-07-05。

    输入

    在这里插入图片描述

    输出

    with t1 as (
        select distinct post_id,extra
        from Actions
        where action='report' and action_date='2019-07-04'
    )
    select extra as  report_reason,count(1) as report_count
    from t1
    group by extra
    ;
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    在这里插入图片描述

  • 相关阅读:
    移动端页面如何优雅的适配各种屏幕,包括PC端
    Ubuntu 22.04安装过程
    海运到美国整柜多少钱?
    闲人闲谈PS之三十二——业务工程预算和PS成本计划
    探索 GAN 和 VAE 之外的 NLP 扩散模型
    黑客技术-小白自学
    【软件部署】Linux源码安装Jenkins
    UE5编译报错:Error MSB3073
    本地搭建wamp服务器并内网穿透实现无公网IP远程访问
    nginx限流 漏桶与令牌桶
  • 原文地址:https://blog.csdn.net/weixin_51696882/article/details/132732139