首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

SQL SERVER 排序有关问题

2013-06-26 
SQL SERVER 排序问题请问下,比如有一组数 13-1,13-12,13-130,14-18,14-22,14-100.要先按‘-’前面的排序,再

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

热点排行