有一个表如下
名称
123456
124657
134564
163456
135443
如何操作能按第二个字符归类排序得出以下结果
类别   名称
2      123456
2      124657
3      134564
3      135443
6      163456

解决方案 »

  1.   

    order by substring(名称,2,1)
      

  2.   

    select substring(名称,2,1) as 类别,名称 from 表 order by 类别
      

  3.   

    select substring(名称,2,1) as 类别,名称 from 表 order by substring(名称,2,1)
      

  4.   


    create table T([name] varchar(20))
    insert T select '123456'
    union all select '124657'
    union all select '134564'
    union all select '163456'
    union all select '135443'
    select [type]=substring([name], 2, 1), [name]
    from T
    order by 1--result
    type name                 
    ---- -------------------- 
    2    123456
    2    124657
    3    134564
    3    135443
    6    163456(5 row(s) affected)
      

  5.   

    select substring(名称,2,1) as 类别,名称 from 表 order by substring(名称,2,1)正解~