日期:2014-05-19  浏览次数:20380 次

求一SELECT查询的排序语句问题,帮帮忙
SELECT   *   FROM   table1   WHERE   ID   IN(10,8,12,22,9,11)
其中表中ID是主键,现在查询ID排序虽然是   10,8,12,22,9,11,
但是查询出来的内容排序会按照ID主键从大到小的顺序
也就是变成了

8
9
10
11
12
22

我想查询出来的内容按
10,8,12,22,9,11这样的顺序排列,不知道有不有办法?


------解决方案--------------------
SELECT IDENTITY(int, 1,1) AS ID_Num,table1.* into #Tmp From table1

select * from #Tmp order by ID_Num
------解决方案--------------------
SELECT a.*
FROM table1 a,(
select oid = 1, id = 10 union all
select oid = 2, id = 8 union all
select oid = 3, id = 12 union all
select oid = 4, id = 22 union all
select oid = 5, id = 9 union all
select oid = 6, id = 11
)b
where a.id = b.id
order by b.oid