将新行插入 table 但从 table 中的另一行复制数据
Insert new rows into table but copy data from another row in the table
我的 ingres 数据库中有一个 table,例如以下值
grd gsd Name Location
112 04 Joe Test
我想用复制的相同数据创建一个新行,但 "grd" 值更改为如下所示的新值
grd gsd Name Location
113 04 Joe Test
如何在优化的 sql 语句中实现此目的?
尝试这样的事情:
INSERT INTO your_table (grd, gsd, Name, Location)
SELECT
grd,--or change it here as you need (for example replacing with value 113)
gsd,
Name,
Location
FROM your_table
--WHERE some condition (e.g. grd = 112)
insert into MyTable(field1, field2, "113")
select field1, field2, grd from MyTable where grd = "112";
我的 ingres 数据库中有一个 table,例如以下值
grd gsd Name Location
112 04 Joe Test
我想用复制的相同数据创建一个新行,但 "grd" 值更改为如下所示的新值
grd gsd Name Location
113 04 Joe Test
如何在优化的 sql 语句中实现此目的?
尝试这样的事情:
INSERT INTO your_table (grd, gsd, Name, Location)
SELECT
grd,--or change it here as you need (for example replacing with value 113)
gsd,
Name,
Location
FROM your_table
--WHERE some condition (e.g. grd = 112)
insert into MyTable(field1, field2, "113")
select field1, field2, grd from MyTable where grd = "112";