← Practice

Рестораны со средним чеком выше городского, 1–14 дек 2025

Questions like this come up in interviews at Самокат

Level: MiddleTopic: Subqueries100 XP

Instructions

Рассмотрите завершённые доставки (status = 'delivered'), созданные (created_at) не раньше 1 декабря 2025 и строго раньше 15 декабря 2025. Средний чек ресторана — среднее amount его таких доставок, средний чек города — среднее amount всех таких доставок ресторанов этого города (по доставкам, а не по средним чекам ресторанов). Выведите рестораны, у которых средний чек строго выше среднего чека их города: id, name, city и avg_check — средний чек ресторана, округлённый до 2 знаков. Порядок строк не важен.

not translated yet

Hints

Each next one is more detailed and costs more

Log in to open hints

Query

Result

Click Run to see the query result, or Check to submit your solution.

Dataset schema

deliveries.restaurant_id (0…N) ↔ restaurants.id (1…1)deliveries.customer_id (0…N) ↔ customers.id (1…1)deliveries.courier_id (0…N) ↔ couriers.id (0…1)couriersPKidintegercustomersPKidintegerdeliveriesPKidintegerFKrestaurant_idintegerFKcustomer_idintegerFKcourier_idintegerrestaurantsPKidinteger
Exactly oneZero or oneZero or more
Table relationships
  • N:1Many-to-onedeliveries.restaurant_id → restaurants.id
  • N:1Many-to-onedeliveries.customer_id → customers.id
  • N:1Many-to-onedeliveries.courier_id → couriers.id

Table data

PostgreSQL

Select a table in the diagram or list to view its rows.

Dataset schema