Skip to content
Advertisement

Track customer loss in redshift

I have a data base that looks like this. It has:

acct_open_dt, or the day the account was opened.

acct_close_dt, or the day the account was closed.

dayssinceopendt, which is TODAY – acct_open_dt if acct_close_dt is null or acct_close_dtacct_open_dt if acct_close_dt is not null.

enter image description here

What I want:

for a day sequence along 1990-01-01 to TODAY I want to find how many customers were active for each day.

My intial thought would be to do

for ALL the days, then sum up each new column, but that would be super manual and super inefficient.

How could I do this better?

(of course I was planning on changing the class from numeric to date, you don’t have to include that in your answer.)

Advertisement

Answer

This may suffice:

This will return only dates that are in your data, but that might be sufficient.

Note that the end date is not considered an active date in this logic.

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