用户购买了很多订单,每个订单有 1 件或多件商品,如下所示:
order 1 > 5 items (5 rows)
order 2 > 3 items (3 rows)
order 3 > 1 item (1 rows)
order 4 > 1 item (1 rows)
我们如何根据 4 个订单的 10 行计算用户平均商品数量是多少?
最佳答案
试试这个:
select userId, count(*)/count(distinct orderNumber) avg_items
from orders
group by userId
关于mysql - 用户在一段时间内购买的平均商品数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27840608/