Skip to content
RED SAGSkills
medium10 pts · first answer countssqlctes

Counting repeat customers with a CTE

orders has two rows for customer 1 and one row each for customers 2 and 3. What does this query return?

WITH per_customer AS (
  SELECT customer_id, COUNT(*) AS n
  FROM orders
  GROUP BY customer_id
  HAVING COUNT(*) > 1
)
SELECT COUNT(*) FROM per_customer;
Choose one answer