mysql - 怎么让 SELECT 1+null 等于 1
阿神
阿神 2017-04-17 14:58:58
0
2
657

怎么让

SELECT 1+null

返回的值等于 1

实际的sql可能是

-- 比如 a为1 b为null 
select `a` + `b` from `foo`;

我想的结果是最后select到的 a + b = 1

阿神
阿神

闭关修行中......

reply all(2)
PHPzhong

It works in mysql, and you can find the corresponding function in other DBs:
select a + ifnull(b, 0) from foo;

左手右手慢动作

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!