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.
当两者都可能为 null 并且 null 应被视为零时,如何将列 a+b 一起添加?
you can use COALESCE()
COALESCE()
COALESCE(a, 0) + COALESCE(b, 0)
or IFNULL()
IFNULL()
IFNULL(a, 0) + IFNULL(b, 0)
在 DDL/DML 中用 IFNULL(a,0)+IFNULL(b,0) 替换 a+b。嗯,这是从 MySQL 的角度来看的。