表名称:table1
字段名:a,b,c
要求的结果是字段a的值和每个a不相同所对应的c字段的个数,要求返回到一个结果集中

解决方案 »

  1.   

    select a,count(*)
    from table 
    group by a
      

  2.   

    这个EASY :)
    select a , count(c) from table1 group by a
      

  3.   

    select a,count(*) as 个数
    from [table1] 
    group by a
      

  4.   


    select a,count(*)
    from table1
    group by a
      

  5.   

    SELECT A,COUNT(DISTINCT A)AS '个数' FROM TABLE1 GROUP BY A??
      

  6.   

    .......select a,count(1) from [table] group by a
      

  7.   

     select a,count(1) from table 
     group by a
      

  8.   


    Select a,count(distinct c) from tb
    group by a
      

  9.   

    没有理解楼主的意思……select a,count(1) as 个数
    from table1
    group by a
    这个是统计table1中a相同的的个数
      

  10.   


    select a,count(c) from table1 group by a
    ?
      

  11.   

    if object_id(N'table1',N'U') is not null
    drop table table1
    create table table1
    (
    a int,
    b int,
    c int
    )
    insert into table1 select 1,1,1
    union all select 2,2,2
    union all select 2,2,2
    union all select 3,3,3
    union all select 4,4,4
    union all select 5,5,5
    select * from table1select a,count(c) as 个数 from table1 group by a
    /*
    a      个数
    1 1
    2 2
    3 1
    4 1
    5 1
    */
      

  12.   

    select a,count(distinct c)
    from table 
    group by a