Repeat customers
Hard
Show the name of customers who placed orders in at least two different months.
Tables: customers(customer_id, name, city, country, joined) · products(product_id, name, category, price) · orders(order_id, customer_id, order_date, status) · order_items(order_id, product_id, quantity, unit_price)
Your query✔ Solved
Show the expected result
| name |
|---|
| Aarav Sharma |
| Liam Walker |
| Sita Gurung |
| Ava Wilson |
| Ethan Nguyen |
| Isla Taylor |
| Lucas Martin |
| Zoe Clarke |
| Hiroshi Tanaka |
| Grace Lee |
| Jack Murphy |
| Chloe Davies |
12 rows
Show a solution
SELECT c.name FROM customers c JOIN orders o ON o.customer_id = c.customer_id GROUP BY c.customer_id HAVING COUNT(DISTINCT strftime('%Y-%m', o.order_date)) >= 2;
SQL used
New to SQL? The free SQL course teaches everything these problems use, with a self-checking exercise in every lesson.