name   class
abc   一班
acc   一班
add   一班
bcc   二班
bbc   二班
from tb group by class
如何看待筛选的结果,有些困惑 

解决方案 »

  1.   

    create table [tb]([name] varchar(3),[class] varchar(4))
    insert [tb]
    select 'abc','一班' union all
    select 'acc','一班' union all
    select 'add','一班' union all
    select 'bcc','二班' union all
    select 'bbc','二班'select class from tb group by class
    --等价于
    select distinct class from tb
    /**
    class 
    ----- 
    二班
    一班
    **/--按班统计人数
    select class,count(1)人数 from tb group by class
    /**
    class 人数          
    ----- ----------- 
    二班    2
    一班    3
    **/
      

  2.   

    很好,增强了我对group的理解
      

  3.   

    很谢谢,马上要去找工作了,你的解决了我的group困惑