mysql update语句

之前只知道修改语句这么写: update student set age=20 where id=1java

如今,知道能够有另外一种写法: update student set age=age+1------>这样会使原来的年龄加一.sql

当须要批量修改的时候,之前都是修改一条,跑一次数据库,由于条件和结果不知道如何在语句中匹配起来,如今有了新的方法:数据库

<update id="updateQuantityByBuyer" parameterType="map">
  update product
    set stock = CASE id 
	    <foreach collection="list" separator="" item="bean">
	  		when #{bean.id}  then stock+#{bean.stock}
	    </foreach>
    END
where id in 
(
<foreach collection="list" separator="," item="bean">
  		${bean.id}
</foreach>
)
</update>

//这是mybaties中进行批量修改库存(根据id,在原有的库存上进行增长)

这样子,一条修改语句就能够了.code

当类型是String的时候:it

update student
	set hoppy=CONCAT(hoppy,#{newHoppy})
where id=#{id}

例如原来的hoppy为"打篮球",你传入的 newHoppy为 ",看电影" ,那最后,hoppy 就为  "打篮球,看电影"io

相关文章
相关标签/搜索