当前位置: 首页 > news >正文

LeetCode 1132.申请的报告2

数据准备

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));
create table if not exists Removals (post_id int, remove_date date);
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', '2', '2019-07-04', 'view', 'None');
insert into Actions (user_id, post_id, action_date, action, extra) values ('2', '2', '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-03', 'view', 'None');
insert into Actions (user_id, post_id, action_date, action, extra) values ('5', '2', '2019-07-03', 'report', 'racism');
insert into Actions (user_id, post_id, action_date, action, extra) values ('5', '5', '2019-07-03', 'view', 'None');
insert into Actions (user_id, post_id, action_date, action, extra) values ('5', '5', '2019-07-03', 'report', 'racism');
Truncate table Removals;
insert into Removals (post_id, remove_date) values ('2', '2019-07-20');
insert into Removals (post_id, remove_date) values ('3', '2019-07-18');

需求

编写一段 SQL 来查找:在被报告为垃圾广告的帖子中,被移除的帖子的每日平均占比,四舍五入到小数点后 2 位。

输入

在这里插入图片描述
在这里插入图片描述

分析

在这里插入图片描述

输出

-- 编写一段 SQL 来查找:在被报告为垃圾广告的帖子中,被移除的帖子的每日平均占比,四舍五入到小数点后 2 位。
with t1 as (select *from Actionswhere extra='spam'
),t2 as (select t1.*,r.post_id as post_r_idfrom t1 left join Removals ron t1.post_id=r.post_id
),t3 as (select action_date,count(post_id) as cnt1,count(post_r_id) as cnt2from t2group by action_date
)
select round(avg(cnt2/cnt1),2) as average_daily_percent
from t3
;

在这里插入图片描述

http://www.lryc.cn/news/165381.html

相关文章:

  • 室内探索无人机,解决复杂环境下的任务挑战!
  • 操作指南 | 如何参与Moonbeam投票委托
  • xxl-job中多节点分片的时候如何在linux服务器开启多个执行器实例?
  • springboot三种注入方式
  • 信息化发展38
  • PMP含金量再升级!北京上海等地可评职称!
  • 动态调用微服务
  • 什么是字符集什么是字符编码
  • Python小项目之Tkinter应用】随机点名/抽奖工具大优化:新增查看历史记录窗口!语音播报功能!修复预览文件按钮等之前版本的bug!
  • mysql drop table 死锁
  • Git零基础入门(Linux版)
  • 二维多孔介质图像的粒度分布研究(Matlab代码实现)
  • 文盘Rust——子命令提示,提高用户体验 | 京东云技术团队
  • 同源策略简介
  • 数据量大,分析困难?试试pandas随机抽样
  • stm32---外部中断
  • 电子企业MES管理系统实施的功能和流程有哪些
  • 代码随想录二刷day24
  • 谷粒商城篇章6 ---- P193-P210 ---- 异步线程池商品详情【分布式高级篇三】
  • gcc中的cc1 collect2
  • 学习day59
  • Go Tip02 指针类型 、值类型和引用类型 、标识符的命名规范
  • CSS中如何实现文字跑马灯效果?
  • 《昆明海晏村:修缮后的新生,历史与现代的完美交融》
  • C++ --- Day02 封装
  • 墨西哥专线清关有什么要求?
  • SpringMVC中的JSR303与拦截器的使用
  • 神经网络 01(介绍)
  • 【element-ui】el-date-picker 之picker-options时间选择区间禁用效果的实现
  • Exchange Serve各版本说明及下载