Skip to content
Advertisement

Count of difference in values by date

I have a data set that contain two columns [date, cust_id].

There is a high churn rate for my customers and I am trying to create two additional columns [new_cust, left_cust] by counting the numbers of cust_id that are new and have left by day respectively.

In the case I have two tables broken out by day, I have no issues by querying:

count of new customers

count of customers who churned

I’m not sure how I would query a single table and compare these values by date. What would be the best approach to getting the correct results? I am using AWS Athena.

Expected results:

Explanation: Assuming 2019-12-08 is the very first date, I have 2 new customers and 0 customers who have churned. 2019-12-09, I have gained 1 new customer “456”, but have 1 customer “321” who has churned. I would have to apply this to a longer range of dates and cust_id.

Advertisement

Answer

Hmmm. I think you want:

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