gpt4 book ai didi

sql - 清点清楚后如何计算平均值?

转载 作者:行者123 更新时间:2023-12-01 21:49:20 26 4
gpt4 key购买 nike

我想清点后取平均值。

这是我当前的查询:

SELECT product_id,
COUNT(DISTINCT shop_id) AS shops,
year,
month,
day
FROM X
GROUP BY product_id, year, month, day

但现在,我想取商店的平均值。我试过这样的事情,但我收到了这个错误:invalidrequestexception

SELECT product_id,
AVG(COUNT(DISTINCT shop_id) AS shops) as avg_shops,
year,
month,
day
FROM X
GROUP BY product_id, year, month, day

最佳答案

像下面这样尝试

with cte as
(
SELECT product_id,
COUNT(DISTINCT shop_id) AS shops,
year,
month,
day
FROM X
GROUP BY product_id, year, month, day
) select product_id,
AVG(shops) AS as avg_shops,
year,
month,
day
FROM cte
GROUP BY product_id, year, month, day

关于sql - 清点清楚后如何计算平均值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59775464/

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