Calculate Weekly, Monthly Watch Hours for Paid Users
Company: Amazon
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: Medium
Interview Round: Technical Screen
video_view_logs
+---------+----------+----------------+------------+------------+
| user_id | video_id | watched_seconds| watch_date | device_type|
+---------+----------+----------------+------------+------------+
| 101 | 55 | 360 | 2023-08-14 | mobile |
| 102 | 60 | 240 | 2023-08-15 | desktop |
| 101 | 58 | 1800 | 2023-08-20 | tablet |
| 103 | 55 | 600 | 2023-08-21 | mobile |
| 104 | 72 | 900 | 2023-08-22 | smart_tv |
##### Scenario
You have a raw event table storing every video view. Product managers need a report of total hours watched per week and per month, segmented by device_type and filtered to paid users only.
##### Question
Write an efficient SQL query (or equivalent pandas code) that returns weekly and monthly aggregated watch hours meeting the above conditions. Explain any windowing or date-trunc techniques you use.
##### Hints
Convert seconds to hours, DATE_TRUNC or to_period for grouping, filter before aggregation to minimize scan size.
Quick Answer: This question evaluates a data scientist's ability to perform time-based aggregations, unit conversion, filtering by user segment, and dimensional segmentation (e.g., device_type) on raw event tables.