Write a query to find churn rate from products
Last updated: August 5, 2025
Quick Overview
Write a SQL query to calculate churn rate from the products table, considering nulls and duplicates.
Brex
August 5, 202514
5
266 solved
Write a SQL query to calculate churn rate from the products table, considering nulls and duplicates.
Data manipulation questions at Brex test your ability to work with real-world datasets. This Onsite question evaluates your SQL proficiency, understanding of data modeling, and ability to derive insights from raw data.
What the Interviewer Expects
- Write syntactically correct SQL with proper JOIN and WHERE clauses
- Use GROUP BY and aggregate functions appropriately
- Handle NULL values correctly in your queries
- Explain the query execution plan at a high level
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- Can you rewrite this without using subqueries?
- What indexes would you create to support this query?
- How would you handle slowly changing dimensions in this scenario?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Problem Understanding
To calculate the churn rate from the products table, we need to understand the data structure involved. The products table typically contains columns such as product_id, customer_id, start_date,...
Approach
- Identify Active and Churned Customers: Use a Common Table Expression (CTE) to first determine the total number of customers and then those who have churned.
- Calculate Churned Customers: ...