现在查询出来的结果:dis_code    type     mc 
200-1        a      材料
200-2        a      杂货
200-3        a      其他
200-1        b      材料
200-2        b      杂货
200-1        c      材料需要得到的结果:xh   dis_code    type      mc 
 1    200-1        a      材料
 2    200-2        a      杂货
 3    200-3        a      其他
 1    200-1        b      材料
 2    200-2        b      杂货
 1    200-1        c      材料

解决方案 »

  1.   


    select xh = right(dis_code,len(dis_code)-charindex('-',dis_code)) from tablename
      

  2.   

    select substr(dis_code,length(dis_code)-1,1) as xh,dist_code,type,mc
    from table 
    order by type
      

  3.   

     晕了.不是这样哈  xh是根据type来的 
      

  4.   

    select ROW_NUMBER() over(partition by [type] order by [type]) as xh,*
    from [表]
      

  5.   

    select * , 编号 = (select count(1) from tb where type= t.type and  substring(dis_code,5,dis_code-4)< t.substring(dis_code,5,dis_code-4)) + 1 from tb tselect * , 编号 = row_number() over(partition by type order by substring(dis_code,5,dis_code-4) ) from tb
      

  6.   

    select xh = (select count(1) from tb b where b.type= a.type and b.dis_code <= a.dis_code),* from tb a