Skip to content
Advertisement

Count of past instances in an appended table

This is my desired output:

‘CountOfUsersBought’ I want it to be Amongst All Targeted Users.

And the Table (Updated Daily) from where I get the data to fill the previous output has the following structure:

I want to store on the variable ‘CountOfUsersBought’ the count of all the users that actually bought, not only today but all time. How would you go about doing this query?

Please note that users also buy without an offer, so I only want to count the past instances WHERE EligibleForOffer = 1 AND BoughtToday = 1 AND Timestamp <= ‘CampaignDate’+ 1 day

I know for another table the users that are targeted for each campaign, I just want to keep for more than ‘today’ the count of users that took the offer that was given to them.

Advertisement

Answer

You can GROUP BY dates and use SUM the find how many users eligible for campaigns and use CASE to do your conditions. And bonus is MIN to find which specific user related with the condition is only one user match.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement