导入数据时, 存在的更新, 不存在的插入 无 create?trigger?tr_bank3?on?bank3after?insertasupdate?bank1?set?bank1.fmoney=bank1.fmoney+c.a?from?(select?fid,sum(case?when?type=0?then?fmoney?when?type=1?then?-fmoney?end)?as?a?fr
导入数据时, 存在的更新, 不存在的插入 create?trigger?tr_bank3?on?bank3after?insertas??update?bank1?set?bank1.fmoney=bank1.fmoney+c.a?from?(select?fid,sum(case?when?type=0?then?fmoney?when?type=1?then?-fmoney?end)?as?a?from?bank3?group?by?fid)?c?where?c.fid=bank1.fid?and?exists(select?1?from?inserted?where?fid=bank3.fid))?insert?into?bank1?select?fid,sum(case?when?type=0?then?fmoney?when?type=1?then?-fmoney?end)?as?a?from?bank3?as?awhere?exists(select?1?from?inserted?where?fid=a.fid)and?not?exists(select?1?from?bank1?where?fid=a.fid)group?by?fid
merge [target] tusing [source] s on t.id = s.idwhen matched then update t.name = s.name, t.age = s.age -- use rowset1when not matched then insert values(id,name,age) -- use rowset2when source not matched then delete; -- use rowset3
