码迷,mamicode.com
首页 > 数据库 > 详细

SQL的判断重复新增或者修改

时间:2019-11-26 09:23:08      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:create   values   nbsp   重复   creat   tty   ram   uid   parameter   

<insert id="insertTankStatisticData" parameterType="java.util.Map">
		<selectKey keyProperty="count" resultType="int" order="BEFORE">
			select count(*) AS count from rpt_jiayouzhouqibiao where KehuID=#{KehuID}
 		</selectKey>
 		<if test="count>0">
 			UPDATE rpt_jiayouzhouqibiao SET 
				KehuName = #{KehuName},
				Yewuyuan = #{Yewuyuan},
				Chanpin = #{Chanpin},
				LastTankDate = #{LastTankDate},
				BeforeLastTankDate = #{BeforeLastTankDate},
				Shuliang = #{Shuliang},
				Pingjunshuliang = #{Pingjunshuliang},
				NextTankDate = #{NextTankDate},
				TankPeroid = #{TankPeroid},
				UpdateTime = getDate()
			WHERE KehuID = #{KehuID}
 		</if>
 		<if test="count==0">
 			INSERT INTO rpt_jiayouzhouqibiao(
				KehuID,
				KehuName,
				Yewuyuan,
				Chanpin,
				LastTankDate,
				BeforeLastTankDate,
				Shuliang,
				Pingjunshuliang,
				NextTankDate,
				TankPeroid,
				CreateTime
			) VALUES (
				#{KehuID},
				#{KehuName},
				#{Yewuyuan},
				#{Chanpin},
				#{LastTankDate},
				#{BeforeLastTankDate},
				#{Shuliang},
				#{Pingjunshuliang},
				#{NextTankDate},
				#{TankPeroid},
				getDate()
			)
 		</if>
	</insert>

    

SQL的判断重复新增或者修改

标签:create   values   nbsp   重复   creat   tty   ram   uid   parameter   

原文地址:https://www.cnblogs.com/dahei96/p/11933185.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!