ZZomato·BehavioralL2DSA Round

SQL: Restaurant Billing Year-over-Year Revenue and Average Order Value

viaGlassdoor

Problem: Given a Restaurant table (Restaurant ID, City ID, Name, Owner ID, Brand ID) and a Billing table (Booking ID, Restaurant ID, Order ID, Order Value, Year), write SQL to:

  1. Insert new billing data.
  2. Compute Year-over-Year gross revenue at the city level.
  3. Compute Year-over-Year average order value at the city level.

Example schema: Restaurant(restaurant_id, city_id, name, owner_id, brand_id) Billing(booking_id, restaurant_id, order_id, order_value, year)

Approach: For (2): JOIN Billing to Restaurant on restaurant_id, GROUP BY city_id, year, SUM(order_value), then compute YoY growth using a window function like LAG(sum_revenue) OVER (PARTITION BY city_id ORDER BY year) to compare each year against the previous year for the same city. For (3): same join/group, but AVG(order_value) instead of SUM, with the same LAG-based YoY comparison.

Add a follow-up question they asked
Insert new billing data
asked …
LeaderboardSalary
Language
Account