MySQL 在mysql中用null替换0
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12324931/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
replace 0 with null in mysql
提问by ben
I want to replace 0's in mysql table with 'NULL'. I have read that querying the following way would replace 'NULL' with 0
我想用'NULL'替换mysql表中的0。我已经读过查询以下方式会将“NULL”替换为 0
SELECT COALESCE(null_column, 0) AS null_column FROM whatever;
But how to the other way?
但是反过来呢?
回答by LittleBobbyTables - Au Revtheitroad
You can use NULLIF
, which will return NULL
if the value in the first parameter matches the value in the second parameter.
您可以使用NULLIF
,NULL
如果第一个参数中的值与第二个参数中的值匹配,它将返回。
SELECT NULLIF(null_column, 0) AS null_column FROM whatever
回答by Hawili
update `whatever` set `null_column` = null where null_column = 0;
回答by Giulio Muscarello
Just use an UPDATE
query, it's way faster: UPDATE table SET value=NULL WHERE value=0
.
只需使用UPDATE
查询,它的方式更快:UPDATE table SET value=NULL WHERE value=0
。
回答by Siddharth
I used
我用了
UPDATE userDetails set fame=0 where fame IS NULL;
UPDATE userDetails 设置成名= 0,其中成名为空;
if it to work. Since =
did not work for me.
如果它工作。因为=
对我不起作用。