i have 2 tables:
1.customer (contains customers)
2.customer_order (contains orders)
I want to know this:
no. of customers with 0 orders
no. of customers with 1 order
no. of customers with 2 orders
etc
i have this:
SELECT COUNT(co.id)
FROM customer c
LEFT JOIN customer_order co
ON c.id=co.id_customer
GROUP BY ??? ;
This gives the amount of orders per customer
SELECT co.id Customer, COUNT(*) Orders
FROM customer_order co
GROUP BY co.id_customer;
Now use that as a table, and query it
SELECT Orders, COUNT(*)
FROM (
SELECT co.id Customer, COUNT(*) Orders
FROM customer_order co
GROUP BY co.id_customer;
)
GROUP BY Orders
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With