Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Products in First Week

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

Your question is Top Products in First Week. Start with the requirements and the three 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

Blinkit wants to understand which products new users purchase soon after registration. Write a PostgreSQL query to identify the top five products purchased during each user's first seven days on the platform.

Requirements

  1. Consider orders from registered_at through, but not including, registered_at + INTERVAL '7 days'.
  2. Include only orders with status = 'completed' and non-null matching products.
  3. Rank products by the number of distinct users who purchased them, descending.
  4. Break ties by product_id ascending and return exactly the top five ranked products.

Schema

users
ColumnTypeDescription
user_idPKINTUnique Blinkit user identifier
registered_atTIMESTAMPTimestamp when the user registered
orders
ColumnTypeDescription
order_idPKINTUnique order identifier
user_idINTUser who placed the order
product_idINTPurchased product identifier
ordered_atTIMESTAMPTimestamp when the order was placed
statusVARCHAR(20)Order fulfillment status
products
ColumnTypeDescription
product_idPKINTUnique product identifier
product_nameVARCHAR(100)Product name shown in Blinkit
Tablesusersordersproducts
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results