Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
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
Sign up free to run your codeLog inLn 1
Run your query to see results here.