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
- Count distinct purchasers per week using only transactions with
status = 'completed'. - Return one row per week, even if there are zero active purchasers that week.
- Calculate the prior week's active purchaser count.
- Compute week-over-week growth rate as:
((current_week_active_purchasers - previous_week_active_purchasers) / previous_week_active_purchasers) * 100ReturnNULLwhen the previous week is0or missing. - Order the output by week start date ascending.
Table Definitions
transactions
| column | type | description |
|---|---|---|
| transaction_id | INT | Unique transaction ID |
| user_id | INT | Purchasing user |
| transaction_date | DATE | Date of the transaction |
| amount | DECIMAL(10,2) | Transaction amount |
| status | VARCHAR(20) | Transaction status |
| store_id | INT | Store where the purchase happened |
users
| column | type | description |
|---|---|---|
| user_id | INT | Unique user ID |
| user_name | VARCHAR(100) | User name |
| signup_date | DATE | User signup date |
| country | VARCHAR(50) | User country |
Schema
transactions
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Unique transaction identifier |
| user_id | INT | User who made the transaction |
| transaction_date | DATE | Date the transaction occurred |
| amount | DECIMAL(10,2) | Transaction amount |
| status | VARCHAR(20) | Transaction processing status |
| store_id | INT | Store identifier |
users
| Column | Type | Description |
|---|---|---|
| user_idPK | INT | Unique user identifier |
| user_name | VARCHAR(100) | User full name |
| signup_date | DATE | Date the user signed up |
| country | VARCHAR(50) | User country |
You are practicing as a guest. Sign up free to run your code against the sample data. Your draft stays right here.


