我有两个表(table1
和table2
),我必须验证table2中特定列中的值是否存在于table2中,如果是,则将结果插入到新表中(由table1和table2中的字段组成。
例如:
表1包含以下列:
Imagem
Tipo_Backup
Periocidade
表2包含以下列:
ClientName
Outcome
StartDateTime
EndDateTime
表3需要像这样组成:
Imagem (from table1)
Tipo_Backup (from Table1)
Periocidade (from Table1)
Outcome (from Table2)
StartDatetime (from Table2)
EndDatetime (from Table2)
到目前为止,这是我的代码:
SELECT Imagem, periocidade,
into LGP_tbl_ExecMBackups
FROM LGP_tbl_MapaBackups A
WHERE A.Imagem in
(select REPLACE (B.clientName,'_DB2','')
from Lgp_tbl_import_fx_bocada B)
我不知道如何完成代码来获取table3。
答案 0 :(得分:2)
尝试
INSERT INTO LGP_tbl_ExecMBackups
SELECT
A.Imagem,
A.Tipo_Backup,
A.Periocidade,
B.Outcome,
B.StartDateTime,
B.EndDateTime
FROM LGP_tbl_MapaBackups A
INNER JOIN Lgp_tbl_import_fx_bocada B
ON A.Imagem = REPLACE (B.clientName,'_DB2','')
但是,看起来table1和table2之间没有任何关系。如果您有大量数据,查询将永远完成。