Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rolling Device Activity by Region

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Rolling Device Activity by Region. Start with the requirements and the one table on the right.

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.

Problem

You are given daily device activity data from Resmed devices. Write a PostgreSQL query to return, for each region and calendar date, the number of active devices and the rolling 7-day average of active devices. Treat a device as active on a date when it has at least one activity event that day. Your result should include dates with zero active devices, and the 7-day average should be calculated over the current date plus the previous 6 dates within each region.

Schema

device_activity
ColumnTypeDescription
activity_idPKINTUnique activity event identifier
device_idINTUnique device identifier
regionVARCHAR(50)Geographic region assigned to the device
activity_tsTIMESTAMPTimestamp when the device generated an activity event
activity_typeVARCHAR(30)Type of activity event recorded from the device
Tablesdevice_activity
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results