Zomato: Customers Who Ordered from More Than 3 Restaurants
SQL coding challenge · Difficulty: easy · Topic: Aggregation · +50 XP
Problem
*Asked in a Zomato data interview.*
Zomato wants to reward its explorers: customers who try many different restaurants. Write a query that lists every customer who has ordered at least one dish from more than 3 different restaurants.
- Count different restaurants. Several orders from the same restaurant count as one restaurant.
- Count restaurants, not dishes: the same dish from four restaurants is four restaurants.
- "More than 3" means 4 or more. A customer with exactly 3 restaurants does not qualify.
- Each customer's count uses only their own orders. Every order in the table counts, whatever its date.
- Return each qualifying customer once.
Return user_id, sorted by user_id (the grader checks the rows, not their order).
Schema
Table: orders
| Column | Type | Meaning | | --- | --- | --- | | order_id | INT | Unique id of the order | | user_id | VARCHAR | The customer who placed the order | | restaurant_id | VARCHAR | The restaurant the order came from | | dish_name | VARCHAR | The dish ordered | | order_date | DATE | The day of the order |
Tables
Table: orders
| order_id | user_id | restaurant_id | dish_name | order_date | | --- | --- | --- | --- | --- | | 1 | U123 | R101 | Burger | 2025-01-01 | | 2 | U123 | R102 | Pasta | 2025-01-10 | | 3 | U123 | R103 | Pizza | 2024-12-15 | | 4 | U124 | R102 | Salad | 2024-12-20 | | 5 | U123 | R104 | Burger | 2025-01-05 | | 6 | U125 | R101 | Masala Dosa | 2025-01-03 | | 7 | U125 | R101 | Idli | 2025-01-07 | | 8 | U125 | R102 | Noodles | 2025-01-08 | | 9 | U125 | R103 | Momos | 2025-01-09 | | 10 | U126 | R101 | Biryani | 2024-12-02 | | 11 | U126 | R102 | Biryani | 2024-12-09 | | 12 | U126 | R103 | Biryani | 2024-12-16 | | 13 | U126 | R105 | Biryani | 2024-12-23 |
Expected Output
| user_id | | --- | | U123 | | U126 |
Explanation
- U123 ordered from R101, R102, R103 and R104: 4 restaurants, so U123 qualifies.
- U126 ordered Biryani from R101, R102, R103 and R105: one dish, but 4 restaurants, so U126 qualifies.
- U125 placed 4 orders, but two were from R101: only 3 restaurants (R101, R102, R103), so U125 does not qualify.
- U124 ordered from 1 restaurant.
Notes
- The column name must be exactly
user_id. - The query runs on MySQL 8.
What this SQL challenge teaches you
“Zomato: Customers Who Ordered from More Than 3 Restaurants” is a easy-level SQL challenge focused on Aggregation. Working through it gives you hands-on practice with GROUP BY, HAVING, COUNT DISTINCT, Aggregation, Food Delivery — the kind of transformation you are asked to write in real data engineering work and in technical interviews. You can solve it directly in the browser: the dataset is pre-loaded, so you write the query or DataFrame code, run it, and compare your output against the expected result immediately.
Concepts covered
- GROUP BY
- HAVING
- COUNT DISTINCT
- Aggregation
- Food Delivery
How to approach it
If you get stuck, work through these steps in order before looking at a full solution — each one narrows the problem down:
- Work per customer: GROUP BY user_id.
- COUNT(*) counts orders. You need the number of DIFFERENT restaurants: COUNT(DISTINCT restaurant_id).
- A condition on an aggregate goes in HAVING, not WHERE: HAVING COUNT(DISTINCT restaurant_id) > 3.
- More than 3 is > 3 (or >= 4). >= 3 would also keep customers with exactly 3 restaurants.
Where this comes up
Variations of this problem have been reported in interviews at Zomato. Interviewers use it to check whether you can express the logic cleanly and reason about correctness on edge cases such as ties, nulls and empty groups.
How to practise it on PySpark.in
Open the challenge, write your SQL query in the editor and press Run to execute it against the sample dataset. Submitting checks your output against every test case, including hidden ones, so you find out straight away whether your logic holds up. You can retry as often as you like, and each solved challenge adds to your XP.
Related SQL challenges
- Find Duplicate Emails
- HR: Average Salary by Department
- Logistics: Count Shipments by Status
- Count Total Orders Placed by Each Customer
- Find Average Order Amount for Each Customer
- Find Customers Who Placed More Than 5 Orders (HAVING)
Helpful resources
Frequently asked questions
Do I need to install Spark or a database to solve this?
No. The SQL environment runs in your browser with the sample data already loaded, so there is nothing to install or configure.
Is this challenge free?
Yes - the problem, the sample dataset, the hints and unlimited test runs are free.
What level is it?
It is rated easy and covers Aggregation.