mysql中实现更新数据+1,再次更新数据-1

$sql="update article set comment=comment^1 where a_id=2";

这条语句你会发现当你更新comment字段时为1,再次更新时为0;

comment=comment^1,这是一个位运算,comment的默认值为0,当进行位运算它会变为1,再次位运算会变为0;一直反复;

 

posted @ 2018-11-22 15:40  yunhenX  阅读(4642)  评论(0编辑  收藏  举报