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
Related questions
Using the principles of data visualization clarity emphasized in the certificate, which chart choice and design decision best reduces misinterpretation for comparing distributions between two groups?
View question →
A dashboard shows higher retention for a campaign, but the campaign was only delivered to users after a product change that also improved onboarding. Which causal reasoning statement is the most defensible based on observational data?
View question →
A student reports that mean session duration increased by 30% after a tracking update. Which diagnostic is most appropriate to determine whether the increase is caused by a real behavioral shift versus measurement artifacts like changed sessionization rules?
View question →
You are asked to create a predictive model but suspect label leakage because the label is derived from the same event used as a feature. Which mitigation is most appropriate?
View question →
A data analyst claims that missing values are “missing at random,” but the missingness appears higher for certain user types. Which approach most rigorously tests whether the missingness mechanism could still be MAR for a key feature?
View question →
A dataset includes timestamps in local time for multiple countries, but the reporting dashboard expects UTC. Which transformation is correct for consistent time-based aggregation?
View question →