Bonus periods of 30 days: customer 313
Instructions
A delivery service introduces bonus periods: a customer's first delivery opens a period 30 days long. A delivery belongs to the current period if it was created (created_at) strictly earlier than 30 days after its start (created_at < period start + interval '30 days'); the first delivery created later opens a new period that starts at the moment of its creation. Consider the deliveries of the customer with customer_id = 313, excluding cancelled ones (status = 'cancelled'). For each period, output period_start (created_at of the delivery that opened the period), deliveries_cnt (the number of deliveries in the period) and amount_total (the sum of their amount). Sort by period_start 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
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
Select a table in the diagram or list to view its rows.