My-sql批量更新或者插入的SQL,高效, MyBatis中的配置sample 如下:
<update id="batchUpdate" parameterType="java.util.List">
INSERT INTO db_log.test1 ( a,b,c) values
<foreach collection="list" item="it" index="index" separator=",">
(
#{it.a},#{it.b},#{it.c}
)
</foreach>
on duplicate key update b=b+VALUES(b) , c=c+values(c)
</update>
INSERT INTO stat_day (ymd,ad_id,sno,media_id,cno,req_num,req_num_valid,req_num_ad,req_num_media,tm) VALUES
('2013-09-25',1724,'aduu','9E7F1AE833','',4,3,2,1,NOW()),
('2013-09-25',1724,'aduu','9E7F1AE833','',4,3,2,1,NOW()),
('2013-09-25',1394,'aduu','9E7F1AE833','',4,3,2,1,NOW()),
('2013-09-25',1394,'aduu','9E7F1AE833','',4,3,2,1,NOW()),
('2013-09-25',1724,'aduu','9E7F1AE833','',4,3,2,1,NOW()),
('2013-09-25',1724,'aduu','9E7F1AE833','',4,3,2,1,NOW())
ON DUPLICATE KEY UPDATE req_num=req_num+VALUES(req_num),req_num_valid=req_num_valid+VALUES(req_num_valid),
req_num_ad=req_num_ad+VALUES(req_num_ad),req_num_media=req_num_media+VALUES(req_num_media);