我想使用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
);
答案 0 :(得分:0)
试试这个:
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
关键字。