在MySQL中将null替换为0 [英] Replace null with 0 in MySQL
本文介绍了在MySQL中将null替换为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在MySQL的操作结果中得到了NULL
值.
I am getting NULL
values in the results of an operation in MySQL.
是否可以将NULL
值转换为值0?
Is there a way to convert the NULL
values into the value 0?
推荐答案
是的,通过使用COALESCE
.
SELECT COALESCE(null_column, 0) AS null_column FROM whatever;
COALESCE遍历您提供的值列表,并返回第一个非空值.
COALESCE goes through the list of values you give it, and returns the first non-null value.
这篇关于在MySQL中将null替换为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文