← Practice

Last purchase per day: KZ, 14 d from February 10, 2025

Level: SeniorTopic: Recursive CTEs200 XP

Instructions

Consider the purchases (purchases) of users with country = 'KZ'. For each day from February 10, 2025 to February 23, 2025 inclusive (14 days), output day (type date), purchases_cnt (the number of such purchases on that day, by purchased_at) and last_amount (the amount of the latest such purchase made no later than the end of that day, including before the start of the period; for equal purchased_at, the one with the greatest id). If there were no purchases on a day, last_amount is carried over from the previous day. Sort by day ascending.

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

events.user_id (0…N) ↔ users.id (1…1)purchases.user_id (0…N) ↔ users.id (1…1)eventsPKidintegerFKuser_idintegerpurchasesPKidintegerFKuser_idintegerusersPKidinteger
Exactly oneZero or oneZero or more
Table relationships
  • N:1Many-to-oneevents.user_id → users.id
  • N:1Many-to-onepurchases.user_id → users.id

Table data

PostgreSQL

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

Dataset schema