Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL: Purchase Rate by Country

EasySQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL: Purchase Rate by Country. Start with the requirements and the one table on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Meta's Product Growth team is reviewing January 2021 conversion across countries for a purchase-oriented surface. The dataset below is a denormalized activity snapshot containing active-user events and purchase counts, similar to a product-growth extract used alongside AARRR Funnel reporting.

Write a PostgreSQL query to calculate the percentage of active users in each country who made at least one purchase during January 2021.

Requirements

  1. Include only active events from January 1 through January 31, 2021.
  2. Count each user once per country, even if the user has multiple activity rows.
  3. Return the country, distinct active-user count, distinct purchaser count, and purchase rate percentage, rounded to two decimals.

Schema

meta_user_activity
ColumnTypeDescription
activity_idPKINTUnique activity-event identifier
user_idINTMeta user identifier
countryVARCHAR(50)User's country
activity_dateDATEDate of the activity event
is_activeBOOLEANWhether the event qualifies as active usage
purchase_countINTPurchases attributed to the user on that event
Tablesmeta_user_activity
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results