SQL一次查出多个字段的COUNT值


一条SQL中,一次性查询出多个字段的COUNT值:

1 select  
2 count(case when (TOFlag='10' or TOFlag='5') then 1 else null end) WaitingPayCount,
3 count(case when (TOFlag='15' OR TOFlag='20') then 1 else null end) WaitingTravelCount,
4 count(case when (TOFlag='40' and TOIsComment='0') then 1 else null end) WaitingComment
5 from [Order] with(nolock)

 

至于SQL Case when 的使用方法,我在网上看到一个比较详细的帖子,就不添足了:Case when 的使用方法


免责声明!

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



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