-1

我想选择按订单数量分组的客户数量。结果应该看起来像这样:

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

谢谢你的帮助。

4

1 回答 1

0

如果我理解正确:

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    
于 2016-10-26T08:23:10.760 回答