Last active
April 11, 2024 21:51
-
-
Save x3mxray/df25c85e898bbfa953e1e0c09995f1da to your computer and use it in GitHub Desktop.
Sitecore CDP Batch Segmentation - Risky of churn customers
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 g.meta_ref as guest_ref | |
FROM ( | |
SELECT o.meta_guest_ref, | |
NTILE(5) OVER (ORDER BY R DESC) as R_S, | |
NTILE(5) OVER (ORDER BY F ASC) as F_S, | |
NTILE(5) OVER (ORDER BY M ASC) as M_S | |
FROM ( | |
SELECT o.meta_guest_ref, | |
DATE_DIFF('day', max(date(core_ordered_at)), current_date) AS R, | |
COUNT(*) AS F, | |
SUM(o.core_price) AS M | |
FROM orders o | |
WHERE date(o.core_ordered_at) > date('2023-01-01') | |
GROUP BY o.meta_guest_ref | |
) o | |
) | |
INNER JOIN guests g | |
ON meta_guest_ref = g.meta_ref | |
WHERE R_S<3 and F_S=5 and M_S>3 | |
GROUP BY g.meta_ref |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment