Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Transactions with Dense Rank

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

Your question is Top Transactions with Dense Rank. 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

JPMorganChase risk analytics needs to review each customer's largest recent transactions. Write a PostgreSQL query that returns the top three transaction amounts per customer during the past 30 days, relative to CURRENT_DATE.

Requirements

  1. Join transactions to customers to include the customer's name.
  2. Filter transactions to the previous 30 days, including today, and exclude rows with a NULL amount.
  3. Use DENSE_RANK() partitioned by customer and ordered by amount descending.
  4. Return every transaction with a dense rank of 3 or less, including ties, ordered by customer and amount descending.

Schema

customers
ColumnTypeDescription
customer_idPKINTEGERUnique customer identifier
customer_nameVARCHAR(100)Customer's full name
transactions
ColumnTypeDescription
transaction_idPKINTEGERUnique transaction identifier
customer_idINTEGERCustomer associated with the transaction
transaction_timestampTIMESTAMPDate and time when the transaction occurred
amountNUMERIC(12,2)Transaction amount
transaction_typeVARCHAR(30)Transaction classification
Tablescustomerstransactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results