本文介绍了使用select语句替换sql中的null值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
该怎么做?可以使用 select 语句(其中所有空值都应替换为123)来写什么查询?
Ho to do this?What query can be written by using select statement where all nulls should be replaced with 123?
我知道我们可以使用y做到这一点, 更新表名设置字段名="123",其中字段名为空;
I know we can do this y using, update tablename set fieldname = "123" where fieldname is null;
但不能使用 select 语句来做到这一点.
but can't do it using select statement.
推荐答案
在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
这篇关于使用select语句替换sql中的null值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!