比如说我查询一个表后得到如下结果
name ids
a    12
b    0
c    13
d    0
ids,0为未读信息
其他的数字12,13表示读过(有可能是,15,18之类的)
怎么统计处为0的信息有多少条,其他剩下的多少条?

解决方案 »

  1.   

    select 
    sum(case when ids=0 then 1 else 0 end) as [未读条数],
    sum(case when ids!=0 then 1 else 0 end) as [已读条数]
    from tb
      

  2.   

    select 
    sum(case when ids=0 then 1 else 0 end) as [未读条数],
    sum(case when ids!=0 then 1 else 0 end) as [已读条数]
    from (select .....) t
      

  3.   

    select 
    sum(case when ids=0 then 1 else 0 end) as [未读条数],
    sum(case when ids!=0 then 1 else 0 end) as [已读条数]
    from (查询结果语句) a