Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Second-Highest Client Transaction Amount
00:00
5 left

Second-Highest Client Transaction Amount

MediumSQL · PostgreSQL

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
Interviewer

Your question is Second-Highest Client Transaction Amount. 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.