Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Running Deposit Totals by User

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

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

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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results