1
我有这个SQL语句为我的MySQL数据库。Mysql的空值更改为0
SELECT MAX(customer_ID) AS high_customer_ID FROM `customers`.`customers` WHERE our_customer_ID=1;
但whene疗法是our_customer_ID = 1没有CUSTOMER_ID那么statment返回null,但我想它返回0怎么做呢。
我有这个SQL语句为我的MySQL数据库。Mysql的空值更改为0
SELECT MAX(customer_ID) AS high_customer_ID FROM `customers`.`customers` WHERE our_customer_ID=1;
但whene疗法是our_customer_ID = 1没有CUSTOMER_ID那么statment返回null,但我想它返回0怎么做呢。
您可以使用coalesce
功能在null
的情况下指定一个默认值:
SELECT COALESCE(MAX(customer_ID), 0) AS high_customer_ID
FROM `customers`.`customers`
WHERE our_customer_id = 1;
的可能重复[返回0,如果字段是在MySQL空(http://stackoverflow.com/questions/3997327 /返回-0-IF-场是空合的MySQL) – Stidgeon