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
Rank Top Transactions Per Client
00:00
5 left

Rank Top Transactions Per Client

MediumSQL · PostgreSQL

Problem

How do window functions work? Write a query using ROW_NUMBER() or RANK() to find the top three highest-value transactions for each client account.

Use the provided client_accounts and transactions tables. Return the top three transactions per account, excluding transactions that do not belong to a known account.

Output

  1. One row per selected transaction with account_id, account_name, transaction_id, amount, and transaction_rank
  2. Include up to three transactions per account, ordered by amount descending, with transaction ID as the tie-breaker
  3. Sort by account_id, then transaction_rank, then transaction_id

Schema

client_accounts
ColumnTypeDescription
account_idPKINTUnique client account identifier
account_nameVARCHAR(100)Client account display name
account_typeVARCHAR(30)Type of client account
transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
account_idINTClient account associated with the transaction
amountNUMERIC(12,2)Transaction value
transaction_dateDATEDate the transaction occurred
transaction_typeVARCHAR(30)Transaction classification
Tablesclient_accountstransactions
Interviewer

Your question is Rank Top Transactions Per Client. 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.