No video

Leetcode MEDIUM 1132 - Reported Posts II DISTINCT ROUND AVERAGE - Explained by Everyday Data Science

  Рет қаралды 187

Everyday Data Science

Everyday Data Science

27 күн бұрын

Question: leetcode.com/problems/reporte...
SQL Schema:
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')
Pandas Schema:
data = [[1, 1, '2019-07-01', 'view', None], [1, 1, '2019-07-01', 'like', None], [1, 1, '2019-07-01', 'share', None], [2, 2, '2019-07-04', 'view', None], [2, 2, '2019-07-04', 'report', 'spam'], [3, 4, '2019-07-04', 'view', None], [3, 4, '2019-07-04', 'report', 'spam'], [4, 3, '2019-07-02', 'view', None], [4, 3, '2019-07-02', 'report', 'spam'], [5, 2, '2019-07-03', 'view', None], [5, 2, '2019-07-03', 'report', 'racism'], [5, 5, '2019-07-03', 'view', None], [5, 5, '2019-07-03', 'report', 'racism']]
actions = pd.DataFrame(data, columns=['user_id', 'post_id', 'action_date', 'action', 'extra']).astype({'user_id':'Int64', 'post_id':'Int64', 'action_date':'datetime64[ns]', 'action':'object', 'extra':'object'})
data = [[2, '2019-07-20'], [3, '2019-07-18']]
removals = pd.DataFrame(data, columns=['post_id', 'remove_date']).astype({'post_id':'Int64', 'remove_date':'datetime64[ns]'})
#datascience #mysqltutorials #leetcodesolutions

Пікірлер: 1
@williamlu647
@williamlu647 3 күн бұрын
WITH CTE AS (SELECT distinct a.post_id, a.action_date, r.remove_date, r.post_id AS removed_id, CASE WHEN a.post_id = IFNULL(r.post_id,0) THEN 1 ELSE 0 END AS suu FROM Actions a LEFT JOIN removals r on a.post_id = r.post_id WHERE a.extra = 'spam' and a.action='report') SELECT ROUND(AVG(per)*100,2) AS res FROM( SELECT SUM(suu)/COUNT(*) AS per FROM CTE GROUP BY action_date) T
SPILLED CHOCKY MILK PRANK ON BROTHER 😂 #shorts
00:12
Savage Vlogs
Рет қаралды 10 МЛН
A little girl was shy at her first ballet lesson #shorts
00:35
Fabiosa Animated
Рет қаралды 17 МЛН
I've been using Redis wrong this whole time...
20:53
Dreams of Code
Рет қаралды 348 М.
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 407 М.
[Medium] LeetCode SQL - 626. Exchange Seats
9:07
Cloud Concepts By Chandra
Рет қаралды 190
Stop, Intel’s Already Dead!
13:47
Linus Tech Tips
Рет қаралды 822 М.
6 SQL Joins you MUST know! (Animated + Practice)
9:47
Anton Putra
Рет қаралды 132 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 634 М.