有一个表如下
名称
123456
124657
134564
163456
135443
如何操作能按第二个字符归类排序得出以下结果
类别 名称
2 123456
2 124657
3 134564
3 135443
6 163456
名称
123456
124657
134564
163456
135443
如何操作能按第二个字符归类排序得出以下结果
类别 名称
2 123456
2 124657
3 134564
3 135443
6 163456
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)