怎么让
SELECT 1+null
返回的值等于 1
实际的sql可能是
-- 比如 a为1 b为null
select `a` + `b` from `foo`;
我想的结果是最后select到的 a
+ b
= 1
PHPz2017-04-17 15:00:58
It works in mysql, and you can find the corresponding function in other DBs:
select a
+ ifnull(b
, 0) from foo
;
ringa_lee2017-04-17 15:00:58
The correct answer upstairs, but I think from a database perspective, if an attribute needs to be able to be added and subtracted, then the default value should be set to 0 when designing the database, so that there is no need to use it. ifnul function