Top 3 restaurants by revenue: May–Aug 2025, from 2 km
Level: JuniorTopic: Aggregates, GROUP BY and HAVING50 XP
Instructions
Among the delivered orders (status = 'delivered') with distance_km at least 2, created on or after May 1, 2025 and strictly before September 1, 2025, compute by restaurant the number of deliveries deliveries_cnt and the revenue revenue (the sum of amount). Select restaurant_id, deliveries_cnt, revenue and keep the 3 restaurants with the highest revenue. Sort by revenue descending; for equal revenue, by restaurant_id ascending.
Hints
Each next one is more detailed and costs more
Query
Result
Click Run to see the query result, or Check to submit your solution.
Dataset schema
Exactly oneZero or oneZero or more
Table relationships
- N:1Many-to-one
deliveries.→restaurant_id restaurants.id - N:1Many-to-one
deliveries.→customer_id customers.id - N:1Many-to-one
deliveries.→courier_id couriers.id
Table data
PostgreSQL
Select a table in the diagram or list to view its rows.