1          wu        
2          peng      
3          jiang     
4          wu        
6          jiang     
7          peng      
8          shi       
9          wu        
10         peng      
结果是(先按ID排序,还要把相同的name放在一起)
1 wu
4   wu
9   wu
2    peng
7   peng
10  peng
3   jiang
6   jiang
8    shi

解决方案 »

  1.   

    declare @t table (id int,name varchar(10))
    insert @t select 1 ,'wu'        
    union all select 2 ,'peng'      
    union all select 3 ,'jiang'     
    union all select 4 ,'wu'        
    union all select 6 ,'jiang'     
    union all select 7 ,'peng'      
    union all select 8 ,'shi'       
    union all select 9 ,'wu'      
    union all select 10,'peng'select * from @t a order by (select min(id) from @t b where b.name=a.name),name,id/*
    id          name       
    ----------- ---------- 
    1           wu
    4           wu
    9           wu
    2           peng
    7           peng
    10          peng
    3           jiang
    6           jiang
    8           shi
    */
      

  2.   

    select xh='0'+cast(id as varchar),name from table
    order by xh,name
      

  3.   

    select id ,name from t group by name,id
    order by id
      

  4.   

    declare @t table (id int,name varchar(10))
    insert @t select 1 ,'wu'        
    union all select 2 ,'peng'      
    union all select 3 ,'jiang'     
    union all select 4 ,'wu'        
    union all select 6 ,'jiang'     
    union all select 7 ,'peng'      
    union all select 8 ,'shi'       
    union all select 9 ,'wu'      
    union all select 10,'peng'
    这个是什么意思呢?是自己写的还是?
      

  5.   

    select * from tableName order by name ,id
      

  6.   

    select id ,name from t order by name,id
      

  7.   

    select * from tableName  a order by  name desc ,id
    1 wu
    4 wu
    9 wu
    8 shi
    2 peng
    7 peng
    10 peng
    3 jiang
    6 jiang
      

  8.   

    wht6411(虚心学习,不断提高) ( ) 信誉:100    Blog  2006-11-30 15:36:32  得分: 0  
     
     
       declare @t table (id int,name varchar(10))
    insert @t select 1 ,'wu'        
    union all select 2 ,'peng'      
    union all select 3 ,'jiang'     
    union all select 4 ,'wu'        
    union all select 6 ,'jiang'     
    union all select 7 ,'peng'      
    union all select 8 ,'shi'       
    union all select 9 ,'wu'      
    union all select 10,'peng'
    这个是什么意思呢?是自己写的还是?
    -----------------------------------------  
     
    这是测试数据.
    至于楼上的几位朋友写的 order by name desc,id 纯属数据碰巧.
    如果我第一条数据name='a'呢, desc还不排到最后去了.
      

  9.   

    select id ,name from t group by name,id
    order by id
      

  10.   

    select id ,name 
    from tb 
    order by name,id
      

  11.   

    fcuandy(手中无剑,心中亦无) ( ) 信誉:100    Blog 
    完全正确。
      

  12.   

    =======================
    select id ,name from t order by substring(name,1,1) desc  

    select id ,name from t order by left(name,1,1) desc  
    说明:
    取出NAME字段的第一个字符进行排序即可
    系统会自动按照字母的ASC码排序,就是你要的那种效果
    可以是A,B,C....
    也可以是Z,Y,X...
    ========================
      

  13.   

    select id ,name from t group by name,id 就可以了。