create table a (id_ integer,count_ integer); insert into a values(1,3); insert into a values(3,6); create table b (id_ integer,count_ integer); insert into b values(1,7); insert into b values(2,4); MERGE INTO a USING b ON (a.id_ = b.id_) WHEN MATCHED THEN UPDATE SET count_ = b.count_+a.count_ /* 注意指名count_属于的表 */ WHEN NOT MATCHED THEN INSERT VALUES (b.id_,b.count_); commit; select * from a;
create table test1 (id int,name varchar(20)) go create table test2 (id int,name varchar(20)) go insert into test1(id,name) values(1,'boyi55'),(2,'51cto'),(3,'bbs'),(4,'fengjicai'),(5,'alis') insert into test2(id,name) values(1,'boyi'),(2,'51cto')
merge test2 t --要更新的目标表 using test1 s --源表 on t.id=s.id --更新条件(即主键) when matched --如果主键匹配,更新 then update set t.name=s.name when not matched then insert values(id,name);--目标主未知主键,插入。此语句必须以分号结束
select a.id,a.name as name_1,b.name as name_2 from test1 as a,test2 as b where a.id=b.id
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有