Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
7-Day Rolling Transactions
00:00
5 left

7-Day Rolling Transactions

MediumSQL · PostgreSQL

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
Interviewer

Your question is 7-Day Rolling Transactions. 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.