Last purchase per day: DE, 14 d from May 5, 2025
Level: Senior200 XP
Instructions
Consider the purchases (purchases) of users with country = 'DE'. For each day from May 5, 2025 to May 18, 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
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
events.→user_id users.id - N:1Many-to-one
purchases.→user_id users.id
Table data
PostgreSQL
Select a table in the diagram or list to view its rows.