Oracle数据库group by与case when配合使用


--group by与case when配合使用:
select
A,
count(case when not B is null then A end) as Cnt
from TBL 
group by A

--执行select A,case when not B is null then A end from TBL order by A会发现
--1、符合case when 条件的数据会原样返回,不符合条件的是null


--2、而count函数,不会计算B = null的行。
--3、所以,以上只会计算符合case when条件的count


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM