← Practice

RANK: top 3 days per platform by purchases, Feb 2025

Level: MiddleTopic: Top-N per group100 XP

Instructions

Consider purchases (purchases) made on or after February 1, 2025 and strictly before March 1, 2025; the platform of a purchase is the user's users.platform. For each platform and each calendar day (purchased_at::date) compute the metric purchases: the number of purchases per day; days without purchases are not considered. Within a platform, rank the days by the metric descending using RANK(): days with an equal metric get the same place, and the next place is skipped. Output the days with place <= 3; because of ties there may be more than 3 of them on a platform. Columns: platform, purchase_date (the date), purchases, place. Row order does not matter.

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