我想使用select语句以及唯一值插入到表中。以下查询返回列计数不匹配的错误。我想念什么?
insert into moving_average (ma_symbol, ma_date, ma5)
values
(
select 'A', max(temp.histDate), avg(temp.histClose)
from
(
select hd.histDate, hd.histClose
from historical_data hd
where symbol like 'A' order by hd.histDate asc limit 5
) temp
);
最佳答案
尝试这个:
insert into moving_average (ma_symbol, ma_date, ma5)
select 'A', max(histDate), avg(histClose)
from (select (histDate), (histClose)
from historical_data
where symbol like 'A'
order by histDate asc
limit 5) temp;
INSERT INTO ... SELECT
语句不使用VALUES
关键字。关于mysql - 插入子查询和唯一值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35425059/