Highest Number of Products — eBay Asked SQL Question

  • Post last modified:February 6, 2024
  • Reading time:2 mins read

Photo by Caspar Camille Rubin on Unsplash

Introduction

  • In this article will solve Highest Numbers of Products SQL question which is asked by eBay as per DataLemur website.

If you don’t know DatLemur then please do visit , it’s one of the best website to practice SQL questions and improve your SQL skills.

Question

  • We have been given user_transactions table that consist of orders made by eBay customers.
  • We need to query to get top 3 users who have spent at-least $1000 in total.

Solution

  • We first need to group all the transaction for each user and perform count of products that user purchased.
  • Once we have number of product purchased by each user , we can filter based amount of money user spend . we can do that using Having clause doing sum(spend).
  • Now all we have to filter top 3 records and we have to sort the records based on count of product and total spend.
  • Here is the the final output.

Final Solution

select user_id, count(product_id) as product_num from user_transactions
group by user_id
having sum(spend) >=1000
order by product_num desc, sum(spend) desc
limit 3

Submission

  • Our solution get accepted by the platform.

Conclusion

  • In this article, we solved question asked by eBay. In this particular question we learnt how to use having clause and apply sorted order many columns.

Before You Leave

Leave a Reply