Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Weekly Active Purchaser Growth Rate

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

Your question is Weekly Active Purchaser Growth Rate. Start with the requirements and the two tables 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

ShopWave wants to track how its active purchaser base changes week over week. Write a PostgreSQL query to calculate the weekly count of active purchasers and the week-over-week growth rate.

An active purchaser is a user who has at least one completed transaction in a given calendar week. Use the transaction date to assign each purchase to a week.

Requirements

  1. Count distinct purchasers per week using only transactions with status = 'completed'.
  2. Return one row per week, even if there are zero active purchasers that week.
  3. Calculate the prior week's active purchaser count.
  4. Compute week-over-week growth rate as: ((current_week_active_purchasers - previous_week_active_purchasers) / previous_week_active_purchasers) * 100 Return NULL when the previous week is 0 or missing.
  5. Order the output by week start date ascending.

Schema

transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
user_idINTUser who made the transaction
transaction_dateDATEDate the transaction occurred
amountDECIMAL(10,2)Transaction amount
statusVARCHAR(20)Transaction processing status
store_idINTStore identifier
users
ColumnTypeDescription
user_idPKINTUnique user identifier
user_nameVARCHAR(100)User full name
signup_dateDATEDate the user signed up
countryVARCHAR(50)User country
Tablestransactionsusers
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results