2016-01-23 96 views
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怎麼做呢。

+0

的可能重複[返回0,如果字段是在MySQL空(http://stackoverflow.com/questions/3997327 /返回-0-IF-場是空合的MySQL) – Stidgeon

回答

3

您可以使用coalesce功能在null的情況下指定一個默認值:

SELECT COALESCE(MAX(customer_ID), 0) AS high_customer_ID 
FROM `customers`.`customers` 
WHERE our_customer_id = 1;