数据库更新防止字段为负

update t_topic t set t.follow_time=case when
    (if(isNull(t.follow_time),0,t.follow_time)-1)<0
    then 0 else (if(isNull(t.follow_time),0,t.follow_time)-1) end where id=#{0}

 

if(isNull(t.follow_time),0,t.follow_time)-1 字段初始为0 null 同样可以做-1操作

 

posted @ 2016-08-03 15:07  木木高  阅读(483)  评论(0)    收藏  举报