Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 在聚合函数上使用Select查询插入_Mysql - Fatal编程技术网

Mysql 在聚合函数上使用Select查询插入

Mysql 在聚合函数上使用Select查询插入,mysql,Mysql,参考以下线程: 我试图复制它以及许多其他方法在ma20上插入值,但没有任何效果,我不断地得到以下错误: 错误代码:1054。“字段列表”中的未知列“histClose” 我做错了什么?我怎样才能使这项工作成功 insert into moving_average (ma_symbol, ma_date, ma20) select 'A', max(histDate) as maxHistDate, avg(histClose) as histClose from (select hist

参考以下线程:

我试图复制它以及许多其他方法在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);