ChatGPT
Chat
4d ago
SQL: find customers who churned right after their second invoice
Postgres. Tables: customers(id, created_at), invoices(id, customer_id, paid_at, amount), subscriptions(customer_id, cancelled_at). I want customers w…
[code] Notes: ROW_NUMBER gives each customer’s invoices a rank by date; the second CTE keeps only people with at least two paid invoices. FILTER (WHERE …) is the tidy Postgres way to pivot …