SQL 如何将空表的 MAX() 视为 0 而不是 NULL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15475059/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to treat MAX() of an empty table as 0 instead of NULL
提问by Mariusz Jamro
I try to select max value from table
我尝试从表中选择最大值
SELECT MAX(cid) FROM itemconfiguration;
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 ?
但是,当表itemconfiguration
为空时,MAX(cid)
语句被评估为,NULL
而我需要一个数字。如何处理这个并将其NULL
视为 0 ?
回答by RB.
回答by zibidyum
SELECT NVL(MAX(cid), 0) FROM itemconfiguration;
SELECT NVL(MAX(cid), 0) FROM itemconfiguration;
回答by mrm aadil
Can replace a number when max return null using ISNULL,
可以在 max 返回 null 时使用ISNULL替换数字,
ISNULL(MAX(cid),0) FROM itemconfiguration;