← Amazon Interview Insights

Amazon·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Amazon Data Scientist interview with a SQL-heavy technical screen. The question was straightforward on the surface but had enough wrinkles in the date grouping and filtering logic to trip you up if you weren't careful.

Questions Asked (1)

Q1

Given a raw video view event table with columns like user_id, video_id, watched_seconds, watch_date, and device_type, write an efficient SQL query (or pandas equivalent) that returns total watch hours aggregated by both week and month, broken down by device_type, and limited to paid users only. Walk through any date truncation or windowing logic you use.

Product Analytics & MetricsData ModelingTechnical Trade-offs
Author's notes

The seconds-to-hours conversion is trivial but I almost forgot to filter to paid users before the aggregation, which would have scanned way more data than needed.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the schema and assumptions (e.g., paid user flag, timezone, week definition). Then write a SQL query that filters paid users, truncates watch_date to week and month, and aggregates total watch hours by device_type. Explain the date truncation logic and any performance considerations.

Pro tip: Mention that you would validate the aggregation by checking for double-counting when a week spans two months, and consider using a calendar table for consistent week definitions.

1. Clarify requirements and assumptions

Confirm the definition of 'paid users' (e.g., a separate users table with is_paid flag), the start day of the week (e.g., Monday vs Sunday), and timezone handling for watch_date.

2. Filter and pre-aggregate

Filter the event table to only paid users, then compute total watch hours per user, video, device, and date to reduce data volume before date truncation.

3. Apply date truncation

Use DATE_TRUNC('week', watch_date) and DATE_TRUNC('month', watch_date) to group by week and month. Explain that DATE_TRUNC returns the first day of the period (e.g., Monday for week) and that weeks can span months.

4. Aggregate and format output

Sum watch hours grouped by week, month, and device_type. Ensure the output includes both week and month columns, possibly using a UNION or a single query with both groupings.

5. Optimize and validate

Discuss indexing on watch_date and device_type, partitioning by date, and validating results by cross-checking totals with a different aggregation method.

Key Points to Mention

  • Date truncation functions: DATE_TRUNC in SQL, dt.to_period('W') or resample in pandas.
  • Handling weeks that span two months: weeks are not nested within months, so aggregating by both week and month may require separate queries or a cross join with a calendar table.
  • Performance: filter early, use columnar storage, partition by date, and avoid unnecessary columns.
  • Paid user filtering: join with a users table or use a subquery/CTE to filter paid users before aggregation.
  • Watch hours calculation: watched_seconds / 3600, and consider rounding or decimal precision.
  • Window functions: not strictly needed for aggregation, but could be used for running totals or comparisons if required.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.