读书人

SQL SERVER 排序有关问题

发布时间: 2013-06-26 14:29:32 作者: rapoo

SQL SERVER 排序问题
请问下,比如有一组数 13-1,13-12,13-130,14-18,14-22,14-100.
要先按‘-’前面的排序,再按‘-’后面的排序,如何实现?
输出结果为:
13-1
13-12
13-130
14-18
14-22
14-100
[解决办法]


with tb(a) as(
select '13-1' union all
select '13-12' union all
select '13-130' union all
select '14-18' union all
select '14-22' union all
select '14-100'
)
select * from tb
order by convert(int,left(a,charindex('-',a)-1)),
convert(int,right(a,len(a)-charindex('-',a)))

读书人网 >SQL Server

热点推荐