尝试执行此请求时遇到问题:
[42000][904] SQL compilation error: error line 5 at position 24 invalid identifier 'SRC.AGE'
merge into Test_functionality as target
using (select *
from (values ('36', 1, 25, 2.9, '00000101'), ('37', 1, 25, 2.9, '00000101'), ('38', 1, 25, 2.9, '00000101'), ('39', 1, 25, 2.9, '00000101')))
as src(age, SomeBoolean, SomeNumber, SomeDouble, SomeBinary)
on target.age = src.age
when matched then update set target.age = src.age, target.SomeBoolean = src.SomeBoolean, target.SomeNumber = src.SomeNumber, target.SomeDouble = src.SomeDouble, target.SomeBinary = src.SomeBinary
when not matched then insert (age, SomeBoolean, SomeNumber, SomeDouble, SomeBinary) values (src.age, src.SomeBoolean, src.SomeNumber, src.SomeDouble, src.SomeBinary);
我用的桌子是什么
CREATE TABLE Test_functionality (
age VARCHAR,
SomeBoolean BOOLEAN,
SomeNumber INT,
SomeDouble real,
SomeBinary binary
);
答案 0 :(得分:1)
我找到了解决方法:
merge into Test_functionality as target
using (select column1 age, column2 SomeBoolean, column3 SomeNumber, column4 SomeDouble, column5 SomeBinary
from (values ('36', 1, 25, 2.9, '00000101'), ('37', 1, 25, 2.9, '00000101'), ('38', 1, 25, 2.9, '00000101'), ('39', 1, 25, 2.9, '00000101')))
as src
on target.age = src.age
when matched then update set target.age = src.age, target.SomeBoolean = src.SomeBoolean, target.SomeNumber = src.SomeNumber, target.SomeDouble = src.SomeDouble, target.SomeBinary = src.SomeBinary
when not matched then insert (age, SomeBoolean, SomeNumber, SomeDouble, SomeBinary) values (src.age, src.SomeBoolean, src.SomeNumber, src.SomeDouble, src.SomeBinary);