要回答您的问题,是的,它将只进行一次比赛然后中断。但是,如果您希望逻辑允许在更新中进行条件匹配,则该
CASE语句对此非常有用。
像这样的例子:
MERGE INTO YourTableUSING (VALUES (1, 1, NULL), (0, 0, NULL), (0, 1, NULL), (1, 0, NULL)) T2 (a2,b2,c2)ON a = a2 AND b = b2WHEN MATCHED THEN UPDATe SET c = CASE WHEN a = 1 THEN 0 WHEN b = 1 THEN 1 ELSE NULL END WHEN NOT MATCHED THEN INSERT (a, b) VALUES (a2, b2);SELECT * FROM YourTable ORDER BY a,b;
- SQL小提琴演示
结果:
A B C--------------0 0 (null)0 1 11 0 01 1 0
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)