create table test ( uid varchar(50), uname varchar(50) ) insert into test select '01 ','姓名' union all select '0101','姓名' union all select '0102','姓名' union all select '0103','姓名' union all select '03 ','姓名' union all select '0301','姓名' union all select '0302','姓名' union all select '02 ','姓名' union all select '0201','姓名' union all select '0202','姓名' union all select '10 ','姓名' union all select '1001','姓名' union all select '1002','姓名' select * from test order by uid /* uid uname -------------------------------------------------- -------------------------------------------------- 01 姓名 0101 姓名 0102 姓名 0103 姓名 02 姓名 0201 姓名 0202 姓名 03 姓名 0301 姓名 0302 姓名 10 姓名 1001 姓名 1002 姓名(所影响的行数为 13 行) select * from test order by cast(uid as int) /*uid uname -------------------------------------------------- -------------------------------------------------- 01 姓名 02 姓名 03 姓名 10 姓名 0101 姓名 0102 姓名 0103 姓名 0201 姓名 0202 姓名 0301 姓名 0302 姓名 1001 姓名 1002 姓名(所影响的行数为 13 行)*/ */
我这里执行也是没有问题的啊。试试杰伦的SELECT * FROM TEST ORDER BY CAST(ID AS INT)
(
uid varchar(50),
uname varchar(50)
)
insert into test select
'01 ','姓名' union all select
'0101','姓名' union all select
'0102','姓名' union all select
'0103','姓名' union all select
'03 ','姓名' union all select
'0301','姓名' union all select
'0302','姓名' union all select
'02 ','姓名' union all select
'0201','姓名' union all select
'0202','姓名' union all select
'10 ','姓名' union all select
'1001','姓名' union all select
'1002','姓名' select * from test order by uid
/*
uid uname
-------------------------------------------------- --------------------------------------------------
01 姓名
0101 姓名
0102 姓名
0103 姓名
02 姓名
0201 姓名
0202 姓名
03 姓名
0301 姓名
0302 姓名
10 姓名
1001 姓名
1002 姓名(所影响的行数为 13 行)
select * from test order by cast(uid as int)
/*uid uname
-------------------------------------------------- --------------------------------------------------
01 姓名
02 姓名
03 姓名
10 姓名
0101 姓名
0102 姓名
0103 姓名
0201 姓名
0202 姓名
0301 姓名
0302 姓名
1001 姓名
1002 姓名(所影响的行数为 13 行)*/
*/