表tableID    Commdity_ID
04    010401  020402  0302    120201  210202  35统计 前两位相同的  条数也就是 统计 02和 04 开头的  条数

解决方案 »

  1.   

    declare @t table(id varchar(10),Commdity_ID varchar(10))
    insert into @t values('04','01');
    insert into @t values('0401','02');
    insert into @t values('0402','03');
    insert into @t values('02','12');
    insert into @t values('0201','21');
    insert into @t values('0202','35');select left(id,2),count(Commdity_ID)
    from @t
    group by left(id,2)
      

  2.   

    select count(*) as 条数,left(ID,2) as id
    from table
    group by left(ID,2)
      

  3.   

    select  Substring(ID,0,2),count(Substring(ID,0,2)) from table group by Substring(ID,0,2)
      

  4.   

    select  Substring(ID,0,2),count(Substring(ID,0,2)) from table group by Substring(ID,0,2)
      

  5.   

    忘记说了   ORACLE数据库的  substring  和  left  好像都不支持
      

  6.   

    select count(*) as 条数,substr(ID,1,2) as id 
    from table 
    group by substr(ID,1,2)
      

  7.   

    select count(ID) from 表 where ID='04%' or ID='02%'
      

  8.   

    SUBSTR(string,pos,len)