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 的使用方法

posted @ 2015-08-31 12:13  Eric-Lee  阅读(9920)  评论(0编辑  收藏  举报