Last active
December 18, 2018 02:42
-
-
Save linkerzx/3d799faa5cf4b9df49b71f9eb91a2f49 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
dc.CustomerId, | |
dc.AcquisitionDate, | |
DATEDIFF(ac.ActivityDate, dc.AcquisitionDate) AS DaySinceAcquisition, | |
SUM(ac.D1Purchases) A D1Purchases | |
FROM dim_cust_purchaser dc | |
LEFT OUTER JOIN ( | |
SELECT | |
CustomerId, | |
ActivityDate, | |
SUM(D1Quantity) AS D1Purchases | |
FROM agg_daily_activity | |
WHERE | |
ActivityType IN ('purchase') | |
AND ActivityDate >= '<MIN_DATE>' | |
GROUP BY 1,2 | |
) ac | |
ON dc.CustomerId = ac.CustomerId | |
AND dc.AcquisitionDate <= ac.ActivityDate | |
WHERE | |
dc.AcquisitionDate >= '<MIN_DATE>' | |
GROUP BY 1,2,3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment