gpt4 book ai didi

mysql - 根据产品表中的产品数量统计消费者数量

转载 作者:行者123 更新时间:2023-11-29 15:59:22 24 4
gpt4 key购买 nike

我有一个产品表,其中包含 prodId (产品 id)和消费者 id 列,其中 prodId 是主键,对于每个产品,我们都有 prodId ,现在对于每个产品,我们都有一个消费者,因为消费者可以拥有许多产品,我需要根据他们拥有的产品数量找到人数。

enter image description here

最佳答案

您可以使用两个级别的聚合:

select numproducts, count(*) as numpeople
from (select consumerid, count(*) as numproducts
from product
group by consumerid
) c
group by numproducts
order by numproducts;

关于mysql - 根据产品表中的产品数量统计消费者数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56309223/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com