You have two tables: customers(customer_id, signup_date) and purchases(customer_id, purchase_date, amount). You want monthly revenue for customers who were active (had at least one purchase) in that same month. What SQL strategy best avoids accidentally including customers who purchased only in later months?

Answer

Join purchases to customers with a date filter such as purchase_date within the month being aggregated or pre-aggregate purchases by month, then join to monthly active flags

Explanation

Pre-aggregating purchases by month and basing the “active” condition on purchases within the month prevents contamination from later-period behavior.

Last reviewed: October 2026

Reviewed by FirstInTest Editorial Team

Report an error
QuestionBack to list