Dataford
Interview Guides
Upgrade
All questions/SQL & Data Manipulation/Weekly Active Purchaser Growth Rate

Weekly Active Purchaser Growth Rate

Medium
SQL & Data Manipulation
Asked at 1 company1AggregationsRunning TotalsDate Functions
Also asked at
Publicis Groupe

Problem

Task

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.

Table Definitions

transactions

columntypedescription
transaction_idINTUnique transaction ID
user_idINTPurchasing user
transaction_dateDATEDate of the transaction
amountDECIMAL(10,2)Transaction amount
statusVARCHAR(20)Transaction status
store_idINTStore where the purchase happened

users

columntypedescription
user_idINTUnique user ID
user_nameVARCHAR(100)User name
signup_dateDATEUser signup date
countryVARCHAR(50)User country

Sample Data

transactions

transaction_iduser_idtransaction_dateamountstatusstore_id
10112024-01-0245.00completed10
10212024-01-0320.00completed10
10322024-01-0460.00completed11
10432024-01-0930.00completed10
10522024-01-1025.00failed11
10642024-01-1680.00completed12
10742024-01-1710.00completed12
10852024-01-2350.00pending10
10962024-01-2470.00completed11
110NULL2024-01-2515.00completed11

users

user_iduser_namesignup_datecountry
1Ava Chen2023-12-15US
2Liam Patel2023-12-20CA
3Noah Kim2024-01-05US
4Emma Lopez2024-01-08UK
5Mia Johnson2024-01-12US
6Ethan Brown2024-01-18CA
7Sophia Davis2024-01-22UK
8Lucas Martin2024-01-28NULL

Expected Output

week_startactive_purchasersprevious_week_active_purchaserswow_growth_rate_pct
2024-01-012NULLNULL
2024-01-0812-50.00
2024-01-15110.00
2024-01-22110.00

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

Sample Data

Example 1
Input{"users":[[3,"Noah Kim","2024-01-05","US"],[1,"Ava Chen","2023-12-15","US"],[8,"Lucas Martin","2024-01-28",null],[6,"Ethan Brown","2024-01-18","CA"],[2,"Liam Patel","2023-12-20","CA"],[5,"Mia Johnson","2024-01-12","US"],[7,"Sophia Davis","2024-01-22","UK"],[4,"Emma Lopez","2024-01-08","UK"],["1","Elijah Baker","2024-01-20","AU"],["2","James Allen","2023-12-19","NZ"],["3","James Allen","2024-01-25","CL"],["4","Abigail Perez","2024-01-08","null"],["5","Emily Campbell","2023-12-29","ES"],["6","EmilOutput[["2023-12-25","0","null","null"],["2024-01-01","2","0","null"],["2024-01-08","1","2","-50.00"],["2024-01-15","1","1","0.00"],["2024-01-22","1","1","0.00"],["2024-01-29","1","1","0.00"]]

Problem

Task

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.

Table Definitions

transactions

columntypedescription
transaction_idINTUnique transaction ID
user_idINTPurchasing user
transaction_dateDATEDate of the transaction
amountDECIMAL(10,2)Transaction amount
statusVARCHAR(20)Transaction status
store_idINTStore where the purchase happened

users

columntypedescription
user_idINTUnique user ID
user_nameVARCHAR(100)User name
signup_dateDATEUser signup date
countryVARCHAR(50)User country

Sample Data

transactions

transaction_iduser_idtransaction_dateamountstatusstore_id
10112024-01-0245.00completed10
10212024-01-0320.00completed10
10322024-01-0460.00completed11
10432024-01-0930.00completed10
10522024-01-1025.00failed11
10642024-01-1680.00completed12
10742024-01-1710.00completed12
10852024-01-2350.00pending10
10962024-01-2470.00completed11
110NULL2024-01-2515.00completed11

users

user_iduser_namesignup_datecountry
1Ava Chen2023-12-15US
2Liam Patel2023-12-20CA
3Noah Kim2024-01-05US
4Emma Lopez2024-01-08UK
5Mia Johnson2024-01-12US
6Ethan Brown2024-01-18CA
7Sophia Davis2024-01-22UK
8Lucas Martin2024-01-28NULL

Expected Output

week_startactive_purchasersprevious_week_active_purchaserswow_growth_rate_pct
2024-01-012NULLNULL
2024-01-0812-50.00
2024-01-15110.00
2024-01-22110.00

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

Sample Data

Example 1
Input{"users":[[3,"Noah Kim","2024-01-05","US"],[1,"Ava Chen","2023-12-15","US"],[8,"Lucas Martin","2024-01-28",null],[6,"Ethan Brown","2024-01-18","CA"],[2,"Liam Patel","2023-12-20","CA"],[5,"Mia Johnson","2024-01-12","US"],[7,"Sophia Davis","2024-01-22","UK"],[4,"Emma Lopez","2024-01-08","UK"],["1","Elijah Baker","2024-01-20","AU"],["2","James Allen","2023-12-19","NZ"],["3","James Allen","2024-01-25","CL"],["4","Abigail Perez","2024-01-08","null"],["5","Emily Campbell","2023-12-29","ES"],["6","EmilOutput[["2023-12-25","0","null","null"],["2024-01-01","2","0","null"],["2024-01-08","1","2","-50.00"],["2024-01-15","1","1","0.00"],["2024-01-22","1","1","0.00"],["2024-01-29","1","1","0.00"]]
Practice SQL
PostgreSQL
Open on desktop for the full SQL editor with syntax highlighting and autocomplete.
Up next
AWeekly Shopper Retention RateMediumHelloFreshCompare Weekly User Activity TrendsMediumIntuitWeekly Active SMBs by MonthEasy
Next question