Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for High-Value Users

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

Your question is SQL for High-Value Users. 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

Paytm wants to identify high-value users based on successful transaction activity. Analyze the rolling 30-day window ending 2025-01-31, inclusive, and consider only transactions from 2025-01-02 through 2025-01-31.

Write a PostgreSQL query that returns users with at least 3 successful transactions and successful transaction volume of at least ₹1,000 during this window.

Requirements

  1. Join users to transactions while preserving users without qualifying transactions.
  2. Exclude failed, pending, or null-status transactions and transactions outside the rolling window.
  3. Return user_id, full_name, transaction count, and total successful volume.
  4. Order by total volume descending, transaction count descending, and user_id ascending.

Schema

users
ColumnTypeDescription
user_idPKINTEGERUnique Paytm user identifier
full_nameVARCHAR(100)User's full name
transactions
ColumnTypeDescription
transaction_idPKBIGINTUnique transaction identifier
user_idINTEGERUser associated with the transaction
occurred_atTIMESTAMPTZTimestamp when the transaction occurred
amountNUMERIC(12,2)Transaction amount in INR
statusVARCHAR(20)Transaction status
transaction_typeVARCHAR(30)Type of Paytm transaction
Tablesuserstransactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results