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
SQL for Customer and Repeat Orders
00:00
5 left

SQL for Customer and Repeat Orders

HardSQL · PostgreSQL

Problem

Swiggy's Business Analytics team wants a combined SQL report covering IPL fixture combinations, restaurant customer exclusions, and monthly retention. Write one PostgreSQL query that returns all three analyses in a consistent output format.

Requirements

  1. Generate every unique IPL team pairing so each team plays every other team once. Do not pair a team with itself or duplicate a pairing.
  2. Find customers who ordered from KFC or McDonald's at least once, but never ordered from Burger King. Return their customer details.
  3. Calculate monthly repeat order rate as customers who ordered in both the current and immediately previous calendar month divided by all customers ordering in the current month. Include active customers, repeat customers, and the rate.
  4. Label each result type so the combined output can be separated downstream. Round the rate to four decimal places.

Schema

teams
ColumnTypeDescription
team_idPKINTIPL team identifier
team_nameVARCHAR(50)IPL team name
customers
ColumnTypeDescription
customer_idPKINTSwiggy customer identifier
customer_nameVARCHAR(100)Customer name
cityVARCHAR(50)Customer city
restaurants
ColumnTypeDescription
restaurant_idPKINTRestaurant identifier
restaurant_nameVARCHAR(100)Restaurant brand
orders
ColumnTypeDescription
order_idPKINTOrder identifier
customer_idINTOrdering customer
restaurant_idINTOrdered restaurant
ordered_atDATEOrder date
Tablesteamscustomersrestaurantsorders
Interviewer

Your question is SQL for Customer and Repeat Orders. Start with the requirements and the four 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.