大家帮我检查一下我的SQL语句,好吗?

snowerhuayun 2003-10-20 05:43:58
我的表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 用的有问题,我该如何解决?
...全文
26 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
snowerhuayun 2003-10-21
  • 打赏
  • 举报
回复
高手啊!
sdhdy 2003-10-20
  • 打赏
  • 举报
回复
union all 语句里不能用order by
txlicenhe 2003-10-20
  • 打赏
  • 举报
回复
Select * from table1 order by right(field1,1),field1

Select * from table1 order by charindex(right(field1,1),'1234567890'),field1
liaorui 2003-10-20
  • 打赏
  • 举报
回复
用SQL语句不行吧。没有见过可以这样的。

关注中~~~

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧