Forum

Posted by Neha, Jan. 19, 2022, 12:48 a.m.

Q.181 discussion

Q. 181
Users who watched less than one hour of Netflix
Write a query to find all users who have watched less than 1 hour of content within one week of signing up.
Table 1: netflix_account
col_name | col_type
-------------+---------------------
account_id | bigint
country | character varying(2)
created_dt | date
Table 2: netflix_daily_streaming
Daily aggregated watch time by account by content.
col_name | col_type
--------------+---------------------
date | date
account_id | bigint
content_id | bigint
duration | int -- in seconds
-------------------------------------------------------------------------------------------
SELECT DISTINCT account_id FROM
netflix_account AS a
INNER JOIN netflix_daily_streaming AS s
ON a.account_id = s.account_id
WHERE created_dt - date = 7 AND duration < 3600

Answers

Hey Neha,
I think you are getting close, but the content watch duration is on date, user and content id level, so you need to aggregate the total watch time by summing up the duration.
And there was a bug for the time window.
Leon

does this look ok,? select userID from ( SELECT a.account_id as userID ,sum(s.duration) as wDuration FROM netflix_account a join netflix_daily_streaming s on a.account_id=s.account_id where DATEDIFF(s.date,a.created_dt)+1 <=7 group by a.account_id ) a where wDuration <3600

Sathish Kumar, Feb. 16, 2022, 11:04 a.m.
SQLPad user avatar

Leon (949)

Jan. 19, 2022, 10:29 a.m.