日期:2014-05-17  浏览次数:20777 次

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)))