Skip to content
Advertisement

Flag the date when they return

Story:

For each id , they have a join date to a subscription and when they get rebilled monthly, they have a returning date. The first part of the exercise was to flag consecutive months of returned dates from the join date. Here’s an example:

Objective:

What I would like to add is to flag those who return from a canceled subscription. That flag can be in another column. For example the following results shows that on May 1st 2019 , he returned. This date needs to be flagged:

Fiddle Data:

Current query with flag for consecutive months:

Advertisement

Answer

since you didn’t specify which recurrence of returning as the target to flag, my query flags any non-consecutive date as a return date cause a subscriber could leave and return many times after their join date (the subscriber with [id] 3 technically returned in August and then again in October so that’s returning twice but October is marked as LAST instead based on the data set). i also made it easier to read by adding in start date and end date based on the data set in your fiddle.

you can use this query as a temp table, cte, basis, or whatever to continue to query against if you need to manipulate the data further.

here is the result set from my query:

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