gpt4 book ai didi

mysql - 在聚合函数上使用选择查询插入

转载 作者:行者123 更新时间:2023-11-29 21:25:28 24 4
gpt4 key购买 nike

引用以下主题: Can you use aggregate values within ON DUPLICATE KEY

我尝试复制该方法以及许多其他方法在 ma20 上插入值,但没有任何效果,并且不断收到以下错误:错误代码:1054。“字段列表”中存在未知列“histClose”

我做错了什么以及如何才能完成这项工作?

insert into moving_average (ma_symbol, ma_date, ma20)
select 'A', max(histDate) as maxHistDate, avg(histClose) as histClose
from
(select histDate, histClose
from historical_data
where symbol like 'A'
order by histDate asc
limit 20) temp
on duplicate key update ma20 = values(histClose);

最佳答案

values 关键字采用表中列的名称。 。 。这是将进入该列的值:

insert into moving_average (ma_symbol, ma_date, ma20)
select 'A', max(histDate) as maxHistDate, avg(histClose) as histClose
from (select histDate, histClose
from historical_data
where symbol like 'A'
order by histDate asc
limit 20
) temp
on duplicate key update ma20 = values(ma20);

关于mysql - 在聚合函数上使用选择查询插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35531985/

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