如果没有从select语句中找到结果,我如何得到0? [英] How do I get 0 if no result found from select statement?
本文介绍了如果没有从select语句中找到结果,我如何得到0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果找不到结果,我想得0。
我写的是:
ISNULL - >不工作
COALESCE - >返回NULL而不是零。
IFNULL - > Rerturns Null因为因为没有结果而不是null
我的选择统计。是:
set @ tmp2 =( select ifnull(sum(loadqty), 0 )来自 htreat 其中 bno = batch group by bno);
< br $> b $ b
我的尝试:
我的选择统计。是:
set @ tmp2 =( select ifnull(sum(loadqty), 0 )来自 htreat 其中 bno = batch group by bno);
以上返回NULL
解决方案
尝试:
SET @ tmp2 = IsNull(( SELECT SUM(loadqty) FROM htreat WHERE bno = batch), 0 跨度>);
I want to get 0 if no result found.
I was writing:
ISNULL -> Not working
COALESCE -> Returns NULL not Zero.
IFNULL -> Rerturns Null because because no result ot its not null
My Select Stat. is:
set @tmp2=(select ifnull(sum(loadqty),0) from htreat where bno=batch group by bno);
What I have tried:
My Select Stat. is:
set @tmp2=(select ifnull(sum(loadqty),0) from htreat where bno=batch group by bno);
The above returns NULL
解决方案
Try:
SET @tmp2 = IsNull((SELECT SUM(loadqty) FROM htreat WHERE bno = batch), 0);
这篇关于如果没有从select语句中找到结果,我如何得到0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文