How to treat MAX() of an empty table as 0 instead of NULL

前端 未结 3 1244
情书的邮戳
情书的邮戳 2020-12-29 23:15

I try to select max value from table

SELECT MAX(cid) FROM itemconfiguration;

However when table itemconfiguration is empty th

3条回答
  •  太阳男子
    2020-12-30 00:05

    Just use Coalesce or NVL to handle NULLs.

    The following code will return 0 if MAX(cid) is NULL

    SELECT COALESCE(MAX(cid), 0)
    FROM   itemconfiguration
    

提交回复
热议问题