Restaurant Billing YoY Revenue and AOV
Problem Given a Restaurant table and a Billing table, write SQL to (1) insert new billing data, (2) compute year-over-year gross revenue at the city level, and (3) compute year-over-year average order value at the city level.
Schema
Restaurant(restaurant_id, city_id, name, owner_id, brand_id)Billing(booking_id, restaurant_id, order_id, order_value, year)— joined to Restaurant onrestaurant_id
Output
- One row per (city_id, year) carrying that year's aggregate, the previous year's value, and the YoY change as an absolute delta or a percentage.
- The same shape for both the gross-revenue variant (SUM) and the average-order-value variant (AVG).
Example
- City 1: 2023 revenue 1,000 → 2024 revenue 1,250 → YoY growth +25%.
- City 1: 2023 AOV 200 → 2024 AOV 250 → YoY AOV growth +25%.
asked …