mysql如何实现类似于oracle的merge语句

小编给大家分享一下mysql如何实现类似于oracle的merge语句,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

 定期更新一个表A,但是表的数据来自于另一张表B。
A表和B表的结构一样,
当A表中的数据在B表中不存在时,把B表的数据添加到A表中;
当A表中的数据在B表中存在时(即唯一索引项相同时),把B表中的数据累加到A表中。
insert into tableA 
select
from tableB
on duplicate key update tableA.column= +tableB.column...;
insert into tableA(key1,key2,col1,col2)
select key1,key2,col1,col2
from tableB
on duplicate key update col1=col1+tableB.col1,col2=col2+tableB.col2;
insert into tableA(key1,key2,col1,col2)
select key1,key2,col1,col2
from (here :it also can be a temp table)tableB
on duplicate key update col1=col1+tableB.col1,col2=col2+tableB.col2;

看完了这篇文章,相信你对“mysql如何实现类似于oracle的merge语句”有了一定的了解,如果想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!