使用mysql中的select语句替换sql中的空值? [英] Replace nulls values in sql using select statement in mysql?
本文介绍了使用mysql中的select语句替换sql中的空值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
怎么做?使用 select 语句可以编写什么查询,其中所有空值都应替换为 123?
Ho to do this? What query can be written by using select statement where all nulls should be replaced with 123?
我知道我们可以使用,update tablename set fieldname = "123" where fieldname is null;
I know we can do this y using, update tablename set fieldname = "123" where fieldname is null;
但不能使用 select 语句.
推荐答案
在 MySQL 中替换 NULL 值有很多选择:
You have a lot of options for substituting NULL values in MySQL:
select case
when fieldname is null then '123'
else fieldname end as fieldname
from tablename
select coalesce(fieldname, '123') as fieldname
from tablename
select ifnull(fieldname, '123') as fieldname
from tablename
这篇关于使用mysql中的select语句替换sql中的空值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文