在查询分析器中执行:
select id from table1 where id in(3224,3225,3395,2810,3280,3281,3292)结果确实(按ID又小到大排序了):
2810
3224
3225
3280
3281
3292
3395请问如果能让id按我(3224,3225,3395,2810,3280,3281,3292)中的顺序显示了。PS:我的SQL语句是通过hibernate调用的,所以不能用存储过程什么的
select id from table1 where id in(3224,3225,3395,2810,3280,3281,3292)结果确实(按ID又小到大排序了):
2810
3224
3225
3280
3281
3292
3395请问如果能让id按我(3224,3225,3395,2810,3280,3281,3292)中的顺序显示了。PS:我的SQL语句是通过hibernate调用的,所以不能用存储过程什么的
order by charindex(','+id+',' , ','+'3224,3225,3395,2810,3280,3281,3292'+',')
order by
case id
when 3224 then 1
when 3225 then 2
when 3395 then 3
when 2810 then 4
when 3280 then 5
when 3281 then 6
when 3292 then 7
end
id
from
table1
where
id in(3224,3225,3395,2810,3280,3281,3292)
order by
charindex(','+rtrim(id)+',' , ','+'3224,3225,3395,2810,3280,3281,3292'+',')
select
id
from
table1
where
id in(3224,3225,3395,2810,3280,3281,3292)
order by
charindex(','+rtrim(id)+',' , ',3224,3225,3395,2810,3280,3281,3292,')