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

排序的有关问题。

2012-08-09 
排序的问题。。。。。select * from table where id in(13557,610,3067,215,9139,1313,5705,2156,2486,5913)ord

排序的问题。。。。。
select * from table where id in(13557,610,3067,215,9139,1313,5705,2156,2486,5913)
order by (13557,610,3067,215,9139,1313,5705,2156,2486,5913)



怎么根据 13557,610,3067,215,9139,1313,5705,2156,2486,5913 来排序


[解决办法]

SQL code
select * from table where id in(13557,610,3067,215,9139,1313,5705,2156,2486,5913)order by charindex(rtrim(ID),'13557,610,3067,215,9139,1313,5705,2156,2486,5913')
[解决办法]
探讨

SQL code
select * from table where id in(13557,610,3067,215,9139,1313,5705,2156,2486,5913)
order by charindex(rtrim(ID),'13557,610,3067,215,9139,1313,5705,2156,2486,5913')

[解决办法]
SQL code
select * from table where id in(13557,610,3067,215,9139,1313,5705,2156,2486,5913)order by charindex(','+rtrim(ID)+',',',13557,610,3067,215,9139,1313,5705,2156,2486,5913,')
[解决办法]
或用patindex,要通用需要加上','有条件类似用符号分隔(1,11,111)
这类
SQL code
select * from table where id in(13557,610,3067,215,9139,1313,5705,2156,2486,5913)order by patindex('%,'+rtrim(ID)+',%',',13557,610,3067,215,9139,1313,5705,2156,2486,5913,') 

热点排行