【发布时间】:2018-04-24 06:54:25
【问题描述】:
我有一些记录:
select f1.id, f1.value from table1 f1
minus
select f2.id, f2.value from table2 f2;
我该怎么做? 因为新 col 的值将只是 varchar = "col1"
【问题讨论】:
标签: sql oracle insert oracle12c
我有一些记录:
select f1.id, f1.value from table1 f1
minus
select f2.id, f2.value from table2 f2;
我该怎么做? 因为新 col 的值将只是 varchar = "col1"
【问题讨论】:
标签: sql oracle insert oracle12c
您可以使用 select 语句中的插入
INSERT INTO table
(column1, column2, ... column_n )
SELECT expression1, expression2, ... expression_n
FROM source_table
[WHERE conditions];
更新: 根据你的情况,试试这个:
insert into new_table (id, new_col, value)
select id, 'col1', value from
(select f1.id, f1.value from table1 f1
minus
select f2.id, f2.value from table2 f2)
【讨论】:
试试这个:
INSERT INTO new_table
(id, new_col, val )
SELECT id, 'col1', col2
FROM old_table;
注意:col1 中的单反转-> 选择值作为 col1 而不是 col2 -> 选择列值,即 True/False
【讨论】: