Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Rolling Telemetry Window SQL
00:00
5 left

Rolling Telemetry Window SQL

HardSQL · PostgreSQL

Problem

Write a SQL query using window functions to compute a 7-day rolling average of telemetry events by customer and rank the top customers each week. Use the supplied customer and telemetry event data, include customers with no events, and treat missing event days as zero. Return the top three rank positions per week, including ties.

Output

  1. One row per included customer and calendar week.
  2. Columns: customer_id, customer_name, week_start, weekly_event_count, rolling_7_day_avg, and weekly_rank.
  3. Sort by week_start, weekly_rank, and customer_id.

Schema

customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer display name
telemetry_events
ColumnTypeDescription
event_idPKINTUnique telemetry event identifier
customer_idINTCustomer associated with the event
occurred_atTIMESTAMPTimestamp when the telemetry event occurred
event_typeVARCHAR(50)Telemetry event classification
Tablescustomerstelemetry_events
Interviewer

Your question is Rolling Telemetry Window SQL. Start with the requirements and the two tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.