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.

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

Notes

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

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:

  1. Work per customer: GROUP BY user_id.
  2. COUNT(*) counts orders. You need the number of DIFFERENT restaurants: COUNT(DISTINCT restaurant_id).
  3. A condition on an aggregate goes in HAVING, not WHERE: HAVING COUNT(DISTINCT restaurant_id) > 3.
  4. 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

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.

Solve this challenge free on PySpark.in