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
Running Deposit Totals by User
00:00
5 left

Running Deposit Totals by User

EasySQL · PostgreSQL

Problem

FinFlow wants to monitor recent deposit activity by user. Write a SQL query to calculate each user's cumulative sum of deposits over the last 30 days.

Requirements

  1. Return one row per user and deposit date for deposits made in the last 30 days.
  2. Include only transactions where transaction_type = 'deposit'.
  3. Sum multiple deposits on the same day into a single daily_deposit_amount.
  4. Calculate a running total per user ordered by deposit date.
  5. Return user_id, user_name, deposit_date, daily_deposit_amount, and cumulative_deposit_amount.
  6. Sort the final output by user_id and deposit_date.

Assume the query is run with a reference date of 2024-03-31, so the last 30 days means transaction_date >= DATE '2024-03-02'.

Schema

users
ColumnTypeDescription
user_idPKINTUnique identifier for the user
user_nameVARCHAR(100)Full name of the user
signup_dateDATEDate the user signed up
statusVARCHAR(20)Current account status
transactions
ColumnTypeDescription
transaction_idPKINTUnique identifier for the transaction
user_idINTUser who made the transaction
transaction_dateDATEDate of the transaction
transaction_typeVARCHAR(20)Transaction type such as deposit or withdrawal
amountDECIMAL(10,2)Transaction amount
channelVARCHAR(20)Channel used for the transaction
Tablesuserstransactions
Interviewer

Your question is Running Deposit Totals by User. 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.