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
SQL for High-Value Users
00:00
5 left

SQL for High-Value Users

MediumSQL · PostgreSQL

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
Interviewer

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