Skip to content
Advertisement

Counting rows with a window function

Each customer can have one or multiple accounts (account_id). To find customer churn, all accounts attached to a customer must be closed, i.e. having closed_date

e.g. here customer churn is 2.

How can I get the customer churn in Postgres? Thanks in advance!

Advertisement

Answer

You can use aggregation:

An alternative is count(distinct) and not exists:

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