在 MySQL 中用 0 替换 null [英] Replace null with 0 in MySQL

查看:29
本文介绍了在 MySQL 中用 0 替换 null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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 中用 0 替换 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆