Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

The 4th edition of the Campaign Community Lens newsletter is out now!

SQL for adding data linked to the filtering dimension



This is from the Recipient RFM example where all Recipients are pulled in the initial Query and then we add data linked to the filtering dimension to compute recency, frequency and monetary.

INSERT INTO wkf505995918_2_2 (dPurchaseHistoryMonetary,tsPurchaseHistoryRecency,iPurchaseHistoryFrequency,iPurchaseHistoryKeysPKey0) SELECT DISTINCT   Sum(P0.dAmount), Max(P0.tsDate), Count(P0.iPurchaseHistoryId), P0.iRecipientId FROM NeoPurchaseHistory P0 JOIN wkf505995918_2_1 W ON (W.iLinksKey1_0=P0.iRecipientId)  WHERE (P0.tsDate >= add_months(CAST((GetDate()) AT TIME ZONE 'America/New_York' AS date), -(18))) AND ((P0.iPurchaseHistoryId > 0 OR P0.iPurchaseHistoryId < 0)) GROUP BY P0.iRecipientId

Note the JOIN between the linked NeoPurchaseHistory table and the wkf505995918_2_1 table populated by the initial query. The JOIN is ON the Recipient ID.

0 Replies