如何将一个空表的MAX()视为0而不是NULL [英] How to treat MAX() of an empty table as 0 instead of NULL
本文介绍了如何将一个空表的MAX()视为0而不是NULL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试从表中选择最大值
I try to select max value from table
SELECT MAX(cid) FROM itemconfiguration;
但是,当表itemconfiguration
为空时,当我需要一个数字时,MAX(cid)
语句将被评估为NULL
.如何处理并将NULL
视为0?
However when table itemconfiguration
is empty the MAX(cid)
statements is evaluated to NULL
while i need a number. How to handle this and treat NULL
as 0 ?
推荐答案
Just use Coalesce or NVL to handle NULLs.
如果MAX(cid)
为NULL,以下代码将返回0
The following code will return 0 if MAX(cid)
is NULL
SELECT COALESCE(MAX(cid), 0)
FROM itemconfiguration
这篇关于如何将一个空表的MAX()视为0而不是NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文