大家帮我检查一下我的SQL语句,好吗?
我的表Table1中有字段Field1(int)。
我想实现这个功能:
按field1的末尾位(末尾位是1-0)进行排序,之后再按照field1字段进行排序。
例如:
table1:
field1
----
781
1021
542
32
41
354
排序结果为:
table1:
field1
----
41
781
1021
32
542
354
我设想的语句如下:
select * from table1 where right(field1,1)=1 order by field1 union all select * from table1 where right(field1,1)=2 order by field1 union all
select * from table1 where right(field1,1)=3 order by field1 union all
select * from table1 where right(field1,1)=4 order by field1 union all
select * from table1 where right(field1,1)=5 order by field1 union all
select * from table1 where right(field1,1)=6 order by field1 union all
select * from table1 where right(field1,1)=7 order by field1 union all
select * from table1 where right(field1,1)=8 order by field1 union all
select * from table1 where right(field1,1)=9 order by field1 union all
select * from table1 where right(field1,1)=0 order by field1
但是这样的做法好像order by 用的有问题,我该如何解决?