Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Rolling 7-Day Messages Per Account
00:00
5 left

Rolling 7-Day Messages Per Account

HardSQL · PostgreSQL

Problem

Write a query to find the rolling 7-day average of messages sent per Twilio customer account, accounting for days with zero activity.

Use the provided customer account and message data for January 1 through January 10, 2024. Return every account for every date in that period, including accounts and dates with no messages.

Output

  1. One row per account and calendar date
  2. Columns: account_id, activity_date, message_count, and rolling_7_day_average
  3. The average should include available dates up to seven calendar days, with zero-message dates included
  4. Order by account_id, then activity_date

Schema

customer_accounts
ColumnTypeDescription
account_idPKINTUnique Twilio customer account identifier
account_nameVARCHAR(100)Customer account name
created_atDATEDate the account was created
messages
ColumnTypeDescription
message_idPKINTUnique message identifier
account_idINTCustomer account associated with the message
sent_atTIMESTAMPTimestamp when the message was sent
message_typeVARCHAR(30)Message channel or type
Tablescustomer_accountsmessages
Interviewer

Your question is Rolling 7-Day Messages Per Account. 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.