Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Second-Highest Marketplace Transactions User

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

Your question is Second-Highest Marketplace Transactions User. 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

Meta Marketplace wants to identify the user with the second-highest number of completed transactions. Write a SQL query to return that user.

Requirements

  1. Count only transactions where status = 'completed'.
  2. Return the user or users tied for the second-highest completed transaction count.
  3. Include user_id, user_name, and completed_transaction_count in the output.
  4. Order the final result by user_id ascending.

Schema

users
ColumnTypeDescription
user_idPKINTPrimary key for the user
user_nameVARCHAR(100)Meta Marketplace user name
regionVARCHAR(50)User region
signup_dateDATEDate the user signed up
transactions
ColumnTypeDescription
transaction_idPKINTPrimary key for the transaction
user_idINTUser who initiated the transaction
amountDECIMAL(10,2)Transaction amount
statusVARCHAR(20)Transaction status
transaction_dateDATEDate of the transaction
Tablesuserstransactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results