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