mysql更新增量int字段为空 [英] mysql update increment int field that is null

查看:528
本文介绍了mysql更新增量int字段为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常大的表,其中有两个INT列,这些列在Default上为空.这是一个问题,因为它们是INT字段,因此如果最初将它们设置为0,在很多情况下都会有帮助.

I have a very large table with two INT columns that are null on Default. This is a problem because since they are INT fields, it would help in many cases if they were originally set to 0.

所以我的问题是,有没有办法像这些字段一样对这些字段进行UPDATE和INCREMENT(+1)(默认为空)?顺便说一句..到目前为止我还没有运气,似乎增量仅在默认值= 0时有效

So my questions are, is there a way I can UPDATE and INCREMENT(+1) these fields while they are like this (null on Default)? BTW.. I didn't have luck so far, it seems increment only works when the default=0

.. or是将默认值从null更改为无"的唯一选择.

..or is my only option to Change the Default to none from null

推荐答案

UPDATE TableName SET column = IFNULL(column, 0) + 1 WHERE ...

有关IFNULL的详细信息.如果不是NULL,它将返回第一个参数,否则返回第二个.

More info on IFNULL. It returns the first argument if it is not NULL, the second otherwise.

这篇关于mysql更新增量int字段为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆