我的 mysql 数据库有这条 SQL 语句。
SELECT MAX(customer_ID) AS high_customer_ID FROM `customers`.`customers` WHERE our_customer_ID=1;
但是当没有 customer_ID 且 our_customer_ID = 1 时,语句返回 null 但我希望它返回 0 我该怎么做。
最佳答案
您可以使用 coalesce
在 null
的情况下分配默认值的函数:
SELECT COALESCE(MAX(customer_ID), 0) AS high_customer_ID
FROM `customers`.`customers`
WHERE our_customer_id = 1;
关于Mysql将空值修改为0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34966971/