Select 按订单数分组的客户数
Select number of customers grouped by number of orders
我想select客户数按订单数分组。结果应该看起来像这样:
Number of Orders | Numbers of Customers
---------------------------------------
1 | 29
2 | 16
3 | 23
4 | 26
....
我不知道该怎么做
SELECT COUNT(o.ID), COUNT(o.ID)
FROM ORDERS o
GROUP BY 1
感谢您的帮助。
如果我理解正确的话:
SELECT s.num_of_orders,count(*) as num_of_customers
FROM(
SELECT count(*) as num_of_orders
FROM Orders o
GROUP BY o.customer_id) s
GROUP BY s.num_of_orders
我想select客户数按订单数分组。结果应该看起来像这样:
Number of Orders | Numbers of Customers
---------------------------------------
1 | 29
2 | 16
3 | 23
4 | 26
....
我不知道该怎么做
SELECT COUNT(o.ID), COUNT(o.ID)
FROM ORDERS o
GROUP BY 1
感谢您的帮助。
如果我理解正确的话:
SELECT s.num_of_orders,count(*) as num_of_customers
FROM(
SELECT count(*) as num_of_orders
FROM Orders o
GROUP BY o.customer_id) s
GROUP BY s.num_of_orders