Unit 15 · Subqueries, integer math
Percentages, subqueries and integer division
Repeat purchase rate
Build the per-customer numbers in a subquery first, then summarize them outside it. CASE WHEN inside SUM counts only the rows that meet a condition.
SELECT 100.0 * SUM(CASE WHEN price >= 100 THEN 1 ELSE 0 END)
/ COUNT(*) AS pct_premium
FROM products;Your task
Of the customers who placed at least one order, what percentage placed two or more? Return a single number, rounded to one decimal place.
Tables you will use: orders
Try it in your browserFree, no sign-up. Your query is checked as you go.