Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我尝试从表中选择最大值
SELECT MAX(cid) FROM itemconfiguration;
但是,当表itemconfiguration为空时,当我需要一个数字时,将对MAX(cid)语句进行评估。NULL如何处理这个并NULL视为 0 ?
itemconfiguration
MAX(cid)
NULL
只需使用Coalesce或NVL来处理 NULL。
MAX(cid)如果为 NULL ,以下代码将返回 0
SELECT COALESCE(MAX(cid), 0) FROM itemconfiguration
SELECT NVL(MAX(cid), 0) FROM itemconfiguration;
可以使用ISNULL在 max 返回 null 时替换数字,
ISNULL(MAX(cid),0) FROM itemconfiguration;