表结构:
年级 平均年龄 
1    11        
3    13        
4    14        
2    12
2    2
4    4
1    1
3    3sql输出结果:
年级 学生姓名
1     11
2     12
3     13
4     14
1     1
2     2
3     3
4     4

解决方案 »

  1.   

    Select * From
    (Select TOP 100 Percent * From TableName Where 平均年龄>10 Order By 平均年龄) A
    Union All
    Select * From
    (Select TOP 100 Percent * From TableName Where 平均年龄<10 Order By 平均年龄) A
      

  2.   

    if object_id('test') is not null drop table test
    select 1 as 年级, 11 as 平均年龄
    into test
    union select 3, 13        
    union select 4, 14        
    union select 2, 12
    union select 2, 2
    union select 4, 4
    union select 1, 1
    union select 3, 3
    -------------------------------------
    select *
    from test
    order by 平均年龄/10 desc, 平均年龄
    /*
    年级   平均年龄
    1      11
    2      12
    3      13
    4      14
    1      1
    2      2
    3      3
    4      4
    */
    -------------------------------------
    drop table test
      

  3.   

    select *
    from test
    order by len(cast(平均年龄 as varchar)) desc, 平均年龄