gpt4 book ai didi

mysql - 获取某个类别中产品的平均价格

转载 作者:行者123 更新时间:2023-11-29 06:08:25 27 4
gpt4 key购买 nike

我的数据库如下所示:

Table - Products
products_id
products_price

Table - Products_to_Categories
categories_id
products_id

Table - Products_Descriptions
products_name

Table - Categories_Descriptions
categories_name

还有很多其他列,但这些是我需要的。

我想选择以上所有列,但我也想最终得到每个类别的平均产品价格

我知道它可能会包含 AVG() 函数,但我尝试了一堆不同的查询(我是一个学习者),如果我能找出有效的方法,我会很烦恼。是否可以仅通过一个查询来完成此操作?我现在无法理解它。

如有任何帮助,我们将不胜感激。 :(

最佳答案

以下查询将为一个类别执行此操作,然后您可以更改每个类别的类别 ID。

SELECT AVG(product_price) FROM Products WHERE products_id IN (SELECT products_id FROM Products_to_Categories WHERE categories_id = x)

关于mysql - 获取某个类别中产品的平均价格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10387556/

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