Zomato Interview Questions
Zomato Interview Questions
(Experience 2+ years)
CTC= 19 LPA
1_ Write an SQL query to find the top 5 most-ordered dishes from a given
restaurant.
Input Table: Orders
FROM Orders
GROUP BY DishName
LIMIT 5;
Output Table:
DishName TotalOrders
Burger 7
Pasta 3
2. Write a Query to Retrieve All Orders Placed in the Last 30 Days for a
Specific User
Input Table: Orders
SELECT *
FROM Orders
Output Table:
FROM Orders
Output Table:
TotalRevenue
650
FROM Ratings
GROUP BY RestaurantID
LIMIT 10;
Output Table:
RestaurantID AverageRating
R101 4.67
R102 4.00
R103 4.00
5. Write a query to List All Customers Who Have Ordered at Least One
Dish from More Than 3 Different Restaurants
Input Table: Orders
OrderID UserID RestaurantID DishName OrderDate
SELECT UserID
FROM Orders
GROUP BY UserID
Output Table:
UserID
U123
WITH AvgOrderValue AS (
FROM Orders
GROUP BY RestaurantID
),
OverallAvg AS (
FROM Orders
Output Table:
RestaurantID AvgOrderValue
R102 275.00
7. Write a Query to Group Orders by Cuisine Type and Calculate the Total
Revenue for Each Cuisine
Input Table: Orders
OrderID Cuisine Amount OrderDate
FROM Orders
GROUP BY Cuisine
Output Table:
Cuisine TotalRevenue
Chinese 550
Italian 350
Indian 100
FROM Orders
Output Table:
WITH MonthlyRevenue AS (
FROM Orders
GROUP BY RestaurantID
CASE
END AS RevenueCategory
FROM MonthlyRevenue;
Output Table:
RestaurantID TotalMonthlyRevenue RevenueCategory
10. Write a Query to Find the Top 3 Dishes Sold for Each Restaurant in a
Specific City
Input Table: Orders
WITH RankedDishes AS (
FROM Orders
FROM RankedDishes
Output Table:
11. Use a CTE to Calculate the Monthly Active Users and Their Most
Ordered Dish for the Past 6 Months
Input Table: Orders
WITH RecentOrders AS (
SELECT UserID, DishName, DATE_FORMAT(OrderDate, '%Y-%m') AS Month, COUNT(*) AS
OrderCount
FROM Orders
),
MostOrderedDish AS (
FROM RecentOrders
FROM MostOrderedDish
WHERE Rank = 1;
Output Table:
ReferrerID ReferredID
U101 U102
U102 U103
U103 U104
U104 U105
WITH ReferralChain AS (
FROM Referrals
UNION ALL
FROM Referrals R
FROM ReferralChain;
Output Table:
ReferrerID
U101
U102
ReferrerID
U103
U104
13. Explain How and Why You Would Use a Temporary Table to Calculate a
Customer's Lifetime Value
Explanation: A temporary table is ideal for calculating customer lifetime value (CLV)
because it allows you to store intermediate results, such as total revenue or total orders for
each customer, without impacting the original database structure. This approach improves
performance and simplifies complex queries by breaking them into smaller steps.
Steps:
1. Create a Temporary Table: Store aggregated data (e.g., total spending, number of
orders per customer).
FROM Orders
GROUP BY UserID;
2. Query the Temporary Table: Calculate CLV by joining with other customer data.
FROM TempCustomerRevenue C
14. Write a Query to Retrieve the Top 5 Restaurants With the Fastest
Average Delivery Time
Input Table: Orders
1 R101 30 2025-01-01
2 R102 25 2025-01-02
3 R103 40 2025-01-03
4 R104 20 2025-01-04
5 R105 15 2025-01-05
FROM Orders
GROUP BY RestaurantID
LIMIT 5;
Output Table:
RestaurantID AvgDeliveryTime
R105 15
R104 20
R102 25
R101 30
R103 40
Indexing Strategy:
1. Primary Index:
2. Composite Index:
4. Clustered Index:
5. Consider Partitioning:
o For millions of rows, partition the table by date (e.g., monthly or yearly).
);
This strategy balances read performance, write efficiency, and query execution speed.
16. Write a Query to Identify Customers Who Have Not Placed Any Orders
in the Last 6 Months But Were Active in the Previous 6 Months
Input Table: Orders
1 U101 2024-01-15
2 U102 2024-02-10
3 U103 2024-06-20
4 U101 2024-07-15
5 U102 2024-12-01
WITH LastSixMonths AS (
SELECT UserID
FROM Orders
),
PreviousSixMonths AS (
SELECT UserID
FROM Orders
FROM PreviousSixMonths
UserID
U103
17. Identify the Top 3 Cities With the Highest Percentage of Premium
Customers
Input Table: Orders
WITH CustomerSpending AS (
FROM Orders
),
PremiumCustomers AS (
FROM CustomerSpending
GROUP BY City
),
CityCustomerCount AS (
FROM Orders
GROUP BY City
SELECT P.City,
P.PremiumCount,
CC.TotalCustomers,
FROM PremiumCustomers P
LIMIT 3;
Output Table:
Mumbai 1 1 100.00
Delhi 1 1 100.00
Bangalore 1 2 50.00
18. Detect Users Who Have Placed Multiple Orders Within the Same
Minute From Different Locations
Input Table: Orders
OrderID UserID Location OrderTimestamp
FROM Orders
Output Table:
19. Calculate the Contribution of Each City to the Total Revenue for a
Given Year
Input Table: Orders
WITH CityRevenue AS (
FROM Orders
GROUP BY City
),
TotalRevenue AS (
FROM Orders
SELECT CR.City,
CR.TotalCityRevenue,
Output Table:
20. Retrieve the Top 5 Dishes That Experienced the Highest Surge in
Orders During a Flash Sale
Input Table: Orders
2 Pizza No 2025-01-11
4 Salad No 2025-01-10
SQL Query:
sql
CopyEdit
WITH AverageOrders AS (
FROM Orders
GROUP BY DishName
),
FlashSaleOrders AS (
SELECT DishName, COUNT(*) AS FlashOrders
FROM Orders
GROUP BY DishName
FROM FlashSaleOrders F
LIMIT 5;
Output Table:
Burger 3 1 2