Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Users by Recent Transaction Volume

MediumSQL · PostgreSQL00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the SQL screen.

The question is on your right: Top Users by Recent Transaction Volume. Read through the requirements and the three tables first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

You need to log in / sign up to run or submit.

Problem

FinEdge wants a report of the most active users by recent completed transaction volume. Write a SQL query to return the top 3 users based on completed transactions in the 30-day window ending on 2024-06-30.

Requirements

  1. Use only transactions with status = 'completed'.
  2. Restrict the date range to 2024-05-31 through 2024-06-30, inclusive.
  3. Count only transactions whose card_id belongs to the same user in the cards table.
  4. For each qualifying user, return:
    • user_id
    • full_name
    • country_code
    • total_volume as the sum of ABS(amount)
    • transaction_count
  5. Order by total_volume descending, then user_id ascending.
  6. Return only the top 3 rows.

Schema

users
ColumnTypeDescription
user_idPKINTPrimary key for the user
full_nameVARCHAR(100)User full name
country_codeVARCHAR(2)ISO country code
signup_dateDATEDate the user signed up
transactions
ColumnTypeDescription
transaction_idPKINTPrimary key for the transaction
user_idINTUser who made the transaction
card_idINTCard used for the transaction
amountDECIMAL(12,2)Signed transaction amount
transaction_dateDATEDate of the transaction
statusVARCHAR(20)Transaction status
cards
ColumnTypeDescription
card_idPKINTPrimary key for the card
user_idINTOwner of the card
card_typeVARCHAR(20)Type of card
card_statusVARCHAR(30)Current card status
Tablesuserstransactionscards
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results