我有一个名为 gen 的表,其结构如下所示; gen01是主键
gen01 gen02 gen03
A 2 5
B 7 9
C 3 11
我想复制一行并插入表中。所以我写了一个SQL
insert into gen (gen01, gen02, gen03)
values
(D, select gen02, gen03 from gen where gen01 = A)
,它报告错误“缺少表达式”。什么原因?谢谢。
答案 0 :(得分:3)
尝试一下
insert into gen (gen01, gen02, gen03)
select 'D', gen02, gen03
from gen where gen01 = 'A';
答案 1 :(得分:0)
您可以尝试类似
insert into your_table (c1, c2, ...)
select c1, c2, ...
from your_table
where id = 1
答案 2 :(得分:0)
请使用以下代码。
CREATE TABLE gen(gen01 VARCHAR(100) PRIMARY KEY, gen02 INT, gen03 INT)
INSERT INTO gen(gen01,gen02,gen03)
VALUES('A',2,5),('C',3,11),('B',7,9)
insert into gen (gen01,gen02,gen03)
select 'D' as gen01,gen02,gen03 from gen where gen01='A';
select * from gen;