如表A 
下面有字段 
    F1      F2 
    1        a 
    2        a 
    3        b 
    4        c 
1.查询出A表中所有相同的值得个数如(a 2 b 1 c 1)? 

解决方案 »

  1.   

    select f2,count(1) from tab group by f2
      

  2.   


    SELECT F2,COUNT(0) FROM A GROUP BY F2
      

  3.   

    哪家公司的面试题,还考COUNT
      

  4.   


    create table #table(f1 int,f2 varchar(10))
    insert into #table
    select 1,'a' union all
    select 2,'a' union all
    select 3,'b' union all
    select 4,'c'select f2,count(f2) from #table group by f2
    drop table #table-----------------a 2
    b 1
    c 1
      

  5.   

    select f2,count(f2) from tb group by f2
      

  6.   


    select f2,count(*) as '个数' from A group by f2
      

  7.   

    SELECT F2,COUNT(F1) '个数' FROM TB GROUP BY F2
      

  8.   

    create table A(F1 VARCHAR(10),F2 varchar(10)) 
      insert into a select      1  ,      'a' 
      insert into a select     2  ,      'a' 
      insert into a select     3  ,      'b' 
      insert into a select      4  ,      'c'
    declare @str varchar(100)
    select @str=isnull(@str+' ','')+F2+' '+cast(F1 as varchar(10)) from (select F2,F1=count(1) from a group by F2) a 
    select @str
    go
    drop table a
      

  9.   

    a 2 b 1 c 1(所影响的行数为 1 行)
      

  10.   

    a 2 b 1 c 1(所影响的行数为 1 行)