我有一项任务是将数据从X
表格SCHEMA_A
移至SCHEMA_B
。
问题是表SCHEMA_A.X
有4列(sid
,is_deleted
,c
,d
),而表SCHEMA_B.X
有5列列(sid
,is_deleted
,rid
,c
,d
)。
如何从另一个表中插入列rid的值,在这种情况下我想让查询尽可能动态? 目前我只能想到以某种方式修改此查询
INSERT INTO SCHEMA_B.X
SELECT * FROM SCHEMA_A.X Aa
WHERE A.is_deleted = 'n'
谢谢你
答案 0 :(得分:1)
添加虚拟列
insert into SCHEMA_B.X
select *, 0 as dummy_columm
from SCHEMA_A.X Aa
WHERE A.is_deleted = 'n'
您可以使用NULL
或其他特殊值来表明其来源
答案 1 :(得分:0)
尝试这样做
insert into SCHEMA_B.X (sid,is_deleted,rid,c,d)
select sid,is_deleted,0 as rid,c,d
from SCHEMA_A.X A
WHERE A.is_deleted = 'n'