表结构是这样
ID    Author    Status
1       A          0
2       B          1
3       C          9
4       A          10
5       C          5
6       A          11
查询条件是统计每个人有几条记录是满足Status 在1-10的,0不算,大于10的也不算想要达到的效果是
Author    Num
  A        1
  B        1
  C        2
每个人的名字不用排序,只要统计出来每个人的数目就好,急啊。

解决方案 »

  1.   


    select author,sum(case when status between 1 and 9 then 1 else 0 end) num
    from tb
    group by author
      

  2.   

    select author,
        sum(case when status between 1 and 9 then 1 else 0 end) num
    from tb
    group by author
      

  3.   

    select
     author,sum(case when status between 1 and 9 then 1 else 0 end) num
    from
     tb
    where
     时间字段='xxxx'
    group by
     author
      

  4.   


    select author,sum(case when status between 1 and 9 then 1 else 0 end) num
    from tb
    where 日期 between date1 and date2
    group by author
      

  5.   


    select author,sum(case when status between 1 and 9 then 1 else 0 end) num
    from tb
    where convert(varchar(10),日期,120) between '2011-08-01' and '2011-08-04'
    group by author