sum结果为null时,如果返回值是int型报错

本文介绍了一种使用Oracle SQL进行复杂查询的方法,通过多个表联接及条件筛选,实现了对不同状态的数据进行统计汇总,并针对不同数据库提供了兼容性建议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

	     select nvl(sum(decode(status.CIP_STATUS,5,1,0)),0) as finishNum		 
		   ,nvl(sum(case when globle.CIP_rapidType=2  and status.CIP_STATUS=0  then 1 else 0 end),0) as noApllyVeryRapid                                            
		   ,nvl(sum(case when globle.CIP_rapidType=1  and status.CIP_STATUS=0  then 1 else 0 end),0) as noApllyRapid 
		   ,nvl(sum(case when (globle.CIP_rapidType=0 or globle.CIP_rapidType  is null) and status.CIP_STATUS=0  then 1 else 0 end),0) as noApllyNoRapid 
		   ,nvl(sum(decode(status.CIP_STATUS,0,1,0)),0) as noApplyNum   
		   ,nvl(sum(decode(status.CIP_STATUS,0,0,5,0,1)) ,0)as applyNoFinishNum  
		   , count(status.CIPID) as totalNum    
		   from  CIP_rptCheckSTATUS status
		         ,Cip_globleInfo globle
		    where status.cipid=globle.cipid(+)
			and status.cipid not in(
					select cipid 
					from  Cip_EditInfo 
					where CIP_editType=2 
					and CIP_isDeal=1 )

 为保万无一失,sum前加NVL即可,oracle下用NVL,SQL server 下用isnull

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值