Repeat customers
mediumShow customer ids and names for customers with at least two orders, plus their order counts. Sort by count descending then customer id.
Hospital Database · SQLite
Run your SQL answer to see the returned rows and check it.
SELECT c.customer_id, c.first_name, c.last_name, COUNT(o.order_id) AS order_count FROM customers AS c JOIN orders AS o ON o.customer_id = c.customer_id GROUP BY c.customer_id HAVING COUNT(o.order_id) >= 2 ORDER BY order_count DESC, c.customer_id;