Daily Active Streaming Devices and Hours by Player Model
Last updated: November 29, 2026
Quick Overview
Using devices(device_id, model) and playback_sessions(device_id, session_start, session_end, channel_id), report for each of the last 7 days and each player model the number of devices that streamed and their average streaming hours per active device.
Roku
November 29, 20260
0
0 solved
Using devices(device_id, model) and playback_sessions(device_id, session_start, session_end, channel_id), report for each of the last 7 days and each player model the number of devices that streamed and their average streaming hours per active device.
Roku reports streaming households and streaming hours as core business metrics, and data engineers build the daily tables behind them. The screen checks correct grain (device-day before averaging), date filtering, and that you notice bad session rows.
What the Interviewer Expects
- Aggregates to one row per device per day before averaging
- Defines an active device as one with positive streaming time that day
- Filters invalid sessions where end is not after start
- Uses an inclusive 7-day window relative to an as-of date
- Names the midnight-crossing session problem and picks a rule
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you split a session that crosses midnight across both days?
- How would you make this incremental instead of recomputing 7 days daily?
- How would you compute 7-day active devices (distinct over the window) rather than a daily count?
- Where would you handle device time zones?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
playback_sessions has one row per playback session with start and end timestamps; a device can have many sessions per day. devices maps each device to a model (Express, Ultra, a TV OEM model). I w...
Approach
Two levels. First, per (date, model, device) sum session hours, dropping rows where session_end <= session_start (zero-length or clock-skewed rows). Second, per (date, model) count devices and avera...