表如下
A
A1
A2
A3
B
B1
B2
B3
C
C1现在要得到所有的长度比如A应该有3个,C是1个

解决方案 »

  1.   

    select left(col,1),count(*)-1 as 记录数 from test
    group by left(col,1)
      

  2.   

    group by 里好象不能用left我前面试了一下 我用了一个自查询完成
      

  3.   

    create table test (col varchar(10))
    insert test select 'A'
    insert test select 'A1'
    insert test select 'A2'
    insert test select 'A3'
    insert test select 'B'
    insert test select 'B1'
    insert test select 'B2'
    insert test select 'B3'
    insert test select 'C'
    insert test select 'C1'select left(col,1) as col,count(*)-1 as 记录数 from test
    group by left(col,1)drop table test
      

  4.   

    select distinct left(col,1) as col,count(*)-1 as 记录数 from test
    group by left(col,1)
      

  5.   

    select distinct left(col,1) as col,count(*)-1 as 记录数 from tablename
    group by left(col,1)