← Practice

Top 20% of buyers by purchase days: TR, since April 2025

Level: MiddleTopic: Top-N per group100 XP

Instructions

Consider users from the country 'TR' and their purchases made on or after April 1, 2025; a user's metric days is the number of distinct calendar days on which they have such purchases, and users without purchases are not considered. Within each platform (users.platform), compute cume_dist() for a user by the metric descending: the share of the platform's users whose metric is at least as high as theirs (equal metrics get the same value). Output the users whose cume_dist is at most 0.2 (that is, the top 20%; everyone with an equal metric at the boundary is included or excluded together). Columns: platform, user_id, days. 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