SQL
All Top 50 SQL Interview Questions#23
Calculate Repeat Purchase Rate in SQL
MediumZomatoInterview Question #23
Asked at ZomatoGiven an `orders` table, write a SQL query to calculate the `repeat_purchase_rate` as a percentage: (customers with > 1 order / total customers) * 100, rounded to 2 decimal places.
Input Table: orders
4 rows preview| order_id | customer_id |
|---|---|
| 1 | 101 |
| 2 | 101 |
| 3 | 102 |
| 4 | 103 |
Expected Output Structure1 rows
| repeat_purchase_rate_pct |
|---|
| 33.33 |
Interview Context
Asked frequently in data analyst and business analyst technical rounds. Focus on clean filtering, optimal indexing usage, and unambiguous column selection.
PostgreSQL 15
Ready to execute
Click "Run Query" or press Ctrl + Enter to test your query.
Output will be verified against the test dataset.