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