logo

Back to questions

Highest Number of Products

Easy

This is the same question as problem #5 in the SQL Chapter of Ace the Data Science Interview!

Assume that you are given the table below containing information on various orders made by eBay customers. Write a query to obtain the user IDs and number of products purchased by the top 3 customers; these customers must have spent at least $1,000 in total.

Output the user id and number of products in descending order. To break ties (i.e., if 2 customers both bought 10 products), the user who spent more should take precedence.

Table:

Column NameType
transaction_idinteger
product_idinteger
user_idinteger
spenddecimal

Example Input:

transaction_idproduct_iduser_idspend
1314321324128699.78
1314331313128501.00
15385321341021001.20
24782684761331051.00
24726532551331474.00
1364953677133247.56

Example Output:

user_idproduct_num
1333
1282
1021

PostgreSQL 14

Refer friends to get bonus content & cool prizes.