Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Order Cancellation and Price Range Query
00:00
5 left

Order Cancellation and Price Range Query

MediumSQL · PostgreSQL

Problem

Meesho's grocery analytics team wants to compare assortment pricing and order reliability across two fulfillment locations. Write a PostgreSQL query for calendar year 2024 using the two tables below.

Requirements

  1. Join products to orders using product_id and restrict orders to 2024.
  2. Return each location's minimum price, maximum price, and price range, calculated as maximum price minus minimum price.
  3. Calculate the percentage of orders whose status is Cancelled or Not Delivered, using all 2024 orders as the denominator.
  4. Include locations with products but no 2024 orders, using zero as their failed-order rate.
  5. Rank locations from highest to lowest failed-order rate, using a deterministic alphabetical tie-breaker.

Schema

products
ColumnTypeDescription
product_idPKINTUnique grocery product identifier
product_nameVARCHAR(100)Grocery product name
locationVARCHAR(50)Fulfillment location
priceNUMERIC(10,2)Listed product price in rupees
orders
ColumnTypeDescription
order_idPKINTUnique order identifier
product_idINTOrdered product identifier referencing products.product_id
order_dateDATEDate the order was placed
statusVARCHAR(30)Delivery outcome such as Delivered, Cancelled, or Not Delivered
Tablesproductsorders
Interviewer

Your question is Order Cancellation and Price Range Query. Start with the requirements and the two tables in the Question tab.

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.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.