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 Average Balance Query
00:00
5 left

7-Day Rolling Average Balance Query

MediumSQL · PostgreSQL

Problem

Given a table of daily user balances, write a query to calculate the 7-day rolling average balance for every user at Current (NY).

Assume each row represents a user's balance on a calendar date. The seven-day period includes the current date and six preceding calendar days; missing dates are excluded, and NULL balances are ignored.

Output

  1. One row per user and balance date.
  2. Columns: user_id, balance_date, and rolling_avg_balance.
  3. Sort by user_id, then balance_date ascending.

Schema

daily_user_balances
ColumnTypeDescription
balance_idPKINTUnique balance record identifier
user_idINTCurrent user identifier
balance_dateDATEDate represented by the balance
balanceDECIMAL(12,2)User balance on the recorded date
Tablesdaily_user_balances
Interviewer

Your question is 7-Day Rolling Average Balance Query. Start with the requirements and the one table 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.