gpt4 book ai didi

mysql - 如何使用另一个计算平均值的查询的结果更新MySQL表

转载 作者:行者123 更新时间:2023-11-29 10:23:41 25 4
gpt4 key购买 nike

我想用其他表中所有价格值的平均值更新一个表。似乎无法让它工作。

Update price_avg set price = (select avg(price) from ((select price from table1) union all
(select price from table2) union all
(select price from table3) union all
(select price from table4) union all
(select price from table5) union all
(select price from table6) union all
(select price from table7) )) as t);

以上返回受影响的 0 行。

运行这个确实会给我平均价格;

select avg(price) from ((select price from table1) union all
(select price from table2) union all
(select price from table3) union all
(select price from table4) union all
(select price from table5) union all
(select price from table6) union all
(select price from table7)) as t;

或者,我也很高兴将上述计算的值保存为 PHP 变量,但也无法使其发挥作用。

最佳答案

括号有问题。试试这个:

Update price_avg
set price = (select avg(price)
from ((select price from table1) union all
(select price from table2) union all
(select price from table3) union all
(select price from table4) union all
(select price from table5) union all
(select price from table6) union all
(select price from table7)
) t
);

关于mysql - 如何使用另一个计算平均值的查询的结果更新MySQL表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48738725/

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