如何做到这一点? 使用 select 语句可以编写什么查询,其中所有空值都应替换为 123?
我知道我们可以使用, update tablename set fieldname = "123"where fieldname is null;
但不能使用 select 语句。
最佳答案
在 MySQL 中有很多替换 NULL 值的选项:
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 - 使用 mysql 中的 select 语句替换 sql 中的空值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9877533/