Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Second-Highest Client Transaction Amount

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

Your question is Second-Highest Client Transaction Amount. 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

Write a PostgreSQL query to return the second-highest distinct transaction amount for each client. Include client_id, client_name, and second_highest_amount. Exclude clients that do not have at least two distinct non-NULL transaction amounts.

Schema

ColumnTypeDescription
client_id
client_name
segment
ColumnTypeDescription
transaction_id
client_id
amount
transaction_date

Representative Rows

clients
1Ava PatelInstitutional
4Daniel KimInstitutional
6Farah AliRetail
transactions
1011900.002024-03-12
1021500.002024-02-10
10941100.002024-03-15
1146450.002024-02-21
Tablesclientstransactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results