我只有两张表iex(1)> :"1"
:"1"
iex(2)> :'1'
:"1"
,ForecastBackup
我想从ForecastTotal
表中选择4列并插入ForecasTotal
ForecastBackup
ForecastTotal
我想插入UCPVol UCPVal IBNSINAVol IBNSINAVal
1 1 NULL NULL
2 3 NULL NULL
NULL NULL 1 4
NULL NULL 3 5
NULL NULL 1 6
非空值
我的意思是结果应该是
ForecastBackup
我使用此SQL命令但不起作用
UCPVol UCPVal IBNSINAVol IBNSINAVal
1 1 1 4
2 3 3 5
NULL NULL 1 6
这可能吗?
答案 0 :(得分:1)
从您的输入和输出我认为您需要此查询
INSERT INTO ForecastBackup (UCPVol,UCPVal, IBNSINAVol, IBNSINAVal)
SELECT
A.UCPVol, A.UCPVal, B.IBNSINAVol, B.IBNSINAVal
FROM
ForecastTotal A
LEFT JOIN
ForecastTotal B ON A.UCPVal = B.IBNSINAVol
答案 1 :(得分:0)
试试这个语法:
INSERT INTO column_1 ( val_1, val_from_other_table )
VALUES('val_1', (SELECT val_2 FROM table_2 WHERE val_2 = something))