Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top 10 Spenders SQL

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

Your question is Top 10 Spenders SQL. Start with the requirements and the one table 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

Scopely wants to identify the highest-spending players in MONOPOLY GO! for a player monetization review. Write a SQL query that calculates each player's total positive purchase amount and returns the top 10 players.

Include only purchase records with a strictly positive amount_usd. A player may have multiple purchase records, and players with no qualifying purchases should not appear.

Output

  1. One row per player
  2. Columns named player_id, player_name, and total_spent
  3. total_spent is the player's total qualifying purchase amount
  4. Return at most 10 rows, ordered by total_spent from highest to lowest
  5. Break ties by player_id in ascending order

Schema

player_purchases
ColumnTypeDescription
purchase_idPKINTUnique identifier for the purchase record
player_idVARCHAR(20)Unique identifier for the player
player_nameVARCHAR(100)Display name of the player
amount_usdDECIMAL(10,2)Purchase amount in US dollars; negative values represent refunds
Tablesplayer_purchases
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results