This question evaluates proficiency in SQL data manipulation, including time-windowed aggregation, joins, filtering by status and date, and percentile-based ranking of restaurant revenue using completed orders.

You want to identify orders coming from restaurants whose total revenue is in the bottom 25th percentile.
Assume the following tables:
restaurantsrestaurant_id
(BIGINT, PK)
name
(VARCHAR)
market_id
(BIGINT)
ordersorder_id
(BIGINT, PK)
restaurant_id
(BIGINT, FK → restaurants.restaurant_id)
customer_id
(BIGINT)
order_total
(DECIMAL(10,2)) — revenue for this order (exclude tips)
created_at
(TIMESTAMP)
status
(VARCHAR) — e.g., 'completed', 'canceled'
Write a SQL query to return orders from restaurants whose total completed-order revenue is in the bottom 25% among all restaurants over a specified analysis window.
CURRENT_DATE
.
status = 'completed'
orders.
SUM(order_total)
over the window.
order_id
restaurant_id
order_total
created_at
restaurant_revenue_30d
State any assumptions (e.g., percentile function availability in your SQL dialect).