Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

7-Day Rolling Transactions

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

Your question is 7-Day Rolling Transactions. Start with the requirements and the two tables 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

Featurespace's ARIC Risk Hub analyzes transaction activity by user. Write a PostgreSQL query that calculates a 7-day rolling average of daily transaction counts for each active user during the reporting period from 2024-01-01 through 2024-01-10.

Requirements

  1. Generate one row for every active user and every calendar day in the reporting period, including days with no transactions.
  2. Count transactions per user per day, treating missing activity as zero.
  3. Use a window function partitioned by user and ordered by date to calculate the rolling average over the current day and previous six calendar days.
  4. Return only dates from 2024-01-04 onward, ordered by user and activity date.

Schema

users
ColumnTypeDescription
user_idPKINTEGERUnique user identifier
user_nameVARCHAR(100)User display name
risk_segmentVARCHAR(30)Featurespace risk classification
emailVARCHAR(150)Contact email
transactions
ColumnTypeDescription
transaction_idPKINTEGERUnique transaction identifier
user_idINTEGERUser associated with the transaction
transaction_timestampTIMESTAMPTransaction event timestamp
channelVARCHAR(30)Transaction channel
amountNUMERIC(12,2)Transaction amount
Tablesuserstransactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results