Trying to get the churn rate, obviously. Getting the quotient within each month would be easy but incorrect.
Frankly, I'm totally lost on this one. Would it make more sense to reorganize the output first?

Trying to get the churn rate, obviously. Getting the quotient within each month would be easy but incorrect.
Frankly, I'm totally lost on this one. Would it make more sense to reorganize the output first?

Copyright © 2021 Jogjafile Inc.
I put your data in a table variable (which is SQL Server) to write the query. The actual
SELECTstatement I wrote should work in all RDBMSs - I think it is all ANSI standard SQL. You didn't mention what data you wanted to see, nor did you mention what should happen in MONTH 1 where there is no previous month, but hopefully you will be able to get your final query from seeing this.To do it,
JOINthe table to itself. I use two aliases,d1andd2. Ford1I want to find CHURN andd2I want to find ACTIVE. Also, the MONTHS ofd2should be one less than the MONTHS ofd1. Finally, since I declared the SUM column as anINT, I multiply it by 1.0 to force it to an approximate data type, otherwise the division would come back as zero or a truncatedINT(since it is integer division).The output is:
Again, you might have to modify the query to get exactly what you want.