try this:--drop table tbcreate table tb(v varchar(10))insert tb select '001' union all select '00125' union all select '002' union all select '0032' union all select '011' union all select '012' union all select '02' union all select '111' union all select '1121' union all select '32' goselect * from tb order by LEFT(v,2),SUBSTRING(v,3,1)
直接order. create table tb(v varchar(10)) go insert tb select '001' union all select '00125' union all select '002' union all select '0032' union all select '011' union all select '012' union all select '02' union all select '111' union all select '1121' union all select '32' go select * from tb order by v/* v ---------- 001 00125 002 0032 011 012 02 111 1121 32(10 行受影响)*/ go drop table tb
select * from tb order by LEFT(v,2),SUBSTRING(v,3,1) 实现的就是按前两位,第三位排序
select '001' union all
select '00125' union all
select '002' union all
select '0032' union all
select '011' union all
select '012' union all
select '02' union all
select '111' union all
select '1121' union all
select '32'
goselect *
from tb
order by LEFT(v,2),SUBSTRING(v,3,1)
create table tb(v varchar(10))
go
insert tb
select '001' union all
select '00125' union all
select '002' union all
select '0032' union all
select '011' union all
select '012' union all
select '02' union all
select '111' union all
select '1121' union all
select '32'
go
select *
from tb
order by v/*
v
----------
001
00125
002
0032
011
012
02
111
1121
32(10 行受影响)*/
go
drop table tb
from tb
order by LEFT(v,2),SUBSTRING(v,3,1)
实现的就是按前两位,第三位排序