select 
次序= (select count(1) from TestTable where  编号 = a.编号 and 名称 <= a.名称),
编号 ,名称,其他
from TestTable a
order by  编号,次序

解决方案 »

  1.   

    --环境
    create table TestTable
    (
    编号 varchar(6),
    名称 varchar(10),
    其他 varchar(50)
    )insert into TestTable select '10000',   '北京',     '阿斗随风倒'
    insert into TestTable select '10000',   '河北',     'sfsaadf'
    insert into TestTable select '10000',   '山西',     '23424234'
    insert into TestTable select '10001',   '吃饭',     '随风萨发'
    insert into TestTable select '10001',   '睡觉',     '哈哈'
    insert into TestTable select '10005',   '别想了',   '2234234'
    insert into TestTable select '10006',   '快点',     '3424234'
    insert into TestTable select '10007',   '随风萨发', '速度分散对方'
    insert into TestTable select '10007',   '324',     '随风'--语句
    select 
    次序= (select count(1) from TestTable where  编号 = a.编号 and 名称 <= a.名称),
    编号 ,名称,其他
    from TestTable a
    order by  编号,次序--结果
    次序        编号   名称       其他    
    ----------- ------ ---------- -------------------------------------------------- 
    1           10000  北京         阿斗随风倒
    2           10000  河北         sfsaadf
    3           10000  山西         23424234
    1           10001  吃饭         随风萨发
    2           10001  睡觉         哈哈
    1           10005  别想了       2234234
    1           10006  快点         3424234
    1           10007  324          随风
    2           10007  随风萨发     速度分散对方(所影响的行数为 9 行)
      

  2.   

    select 编号 ,名称,其他
    from TestTable a
    where not exists (select 1 from TestTable where 编号 = a.编号 and 名称 < a.名称)
      

  3.   

    select  编号 ,名称,其他 from TestTable where 次序=1