当前位置: 代码迷 >> Sql Server >> SQL SERVER 排序有关问题
  详细解决方案

SQL SERVER 排序有关问题

热度:24   发布时间:2016-04-24 21:27:46.0
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)))
  相关解决方案