使用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:

CASE

select case 
    when fieldname is null then '123' 
    else fieldname end as fieldname 
from tablename 

COALESCE

select coalesce(fieldname, '123') as fieldname 
from tablename 

IFNULL

select ifnull(fieldname, '123') as fieldname 
from tablename