Calculate the Monthly Share of High-Frequency Customers
Quick Overview
A PostgreSQL interview problem about measuring the monthly percentage of customers who place more than 30 deliveries. It tests calendar-month aggregation, distinct-customer denominators, threshold logic, and precise percentage calculation.
Calculate the Monthly Share of High-Frequency Customers
Company: DoorDash
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: easy
Interview Round: Technical Screen
# Calculate the Monthly Share of High-Frequency Customers
Write one PostgreSQL SELECT statement or CTE query. Do not create, alter, or modify tables.
## Schema
delivery_orders
| column | type | description |
|---|---|---|
| delivery_id | integer | Unique delivery |
| order_place_time | timestamp | Order placement time |
| customer_id | integer | Customer |
| restaurant_id | integer | Restaurant |
| dasher_id | integer | Courier |
## Task
A high-frequency customer places more than 30 deliveries in a calendar month. For every month, calculate the percentage of distinct customers who ordered that month and were high frequency in that same month.
## Required Output
Return order_month as a date, monthly_customers, high_frequency_customers, and high_frequency_pct rounded to two decimal places. Sort by month ascending.
## Constraints
- Count deliveries, not days.
- A customer can be high frequency in one month and not another.
- The denominator includes every distinct customer with at least one delivery that month.
```hint Aggregate customer-months first
Create one row per month and customer with an order count, then aggregate the high-frequency flag.
```
Quick Answer: A PostgreSQL interview problem about measuring the monthly percentage of customers who place more than 30 deliveries. It tests calendar-month aggregation, distinct-customer denominators, threshold logic, and precise percentage calculation.
Calculate the Monthly Share of High-Frequency Customers
Write one PostgreSQL SELECT statement or CTE query. Do not create, alter, or modify tables.
Schema
delivery_orders
column
type
description
delivery_id
integer
Unique delivery
order_place_time
timestamp
Order placement time
customer_id
integer
Customer
restaurant_id
integer
Restaurant
dasher_id
integer
Courier
Task
A high-frequency customer places more than 30 deliveries in a calendar month. For every month, calculate the percentage of distinct customers who ordered that month and were high frequency in that same month.
Required Output
Return order_month as a date, monthly_customers, high_frequency_customers, and high_frequency_pct rounded to two decimal places. Sort by month ascending.
Constraints
Count deliveries, not days.
A customer can be high frequency in one month and not another.
The denominator includes every distinct customer with at least one delivery that month.