P********l 发帖数: 29 | 1 sql 语句为
select id from table where id in (1,2,5,4,3)
能否以1 2 5 4 3 得到排序结果,语句如何写? | B*****g 发帖数: 34098 | 2 mysql is hot now.
http://www.w3schools.com/SQL/sql_orderby.asp
【在 P********l 的大作中提到】 : sql 语句为 : select id from table where id in (1,2,5,4,3) : 能否以1 2 5 4 3 得到排序结果,语句如何写?
| P********l 发帖数: 29 | 3 似乎不能解决我的问题。
我想要记录集结果按照in的括号里面的顺序排列,而不是按照他的id | B*****g 发帖数: 34098 | 4 Got you, don't know much about mysql.
below is my solution for oracle.
CREATE OR REPLACE
TYPE IDCOLLECTION AS TABLE OF NUMBER;
SELECT t1.*
FROM table t1,
(SELECT COLUMN_VALUE id,
ROWNUM seqno
FROM TABLE (idcollection (1,2,5,4,3))) t2
WHERE t1.id = t2.id
ORDER BY t2.seqno;
【在 P********l 的大作中提到】 : 似乎不能解决我的问题。 : 我想要记录集结果按照in的括号里面的顺序排列,而不是按照他的id
| a*******s 发帖数: 324 | 5 stupid solution
select id from table where id = 1 union select id from table where id = 2
union select id from table where id = 5 union .....
【在 P********l 的大作中提到】 : sql 语句为 : select id from table where id in (1,2,5,4,3) : 能否以1 2 5 4 3 得到排序结果,语句如何写?
| B*****g 发帖数: 34098 | 6 see "stupid solution", think you are replying my post.
haha. btw ,should be "union all" ba
【在 a*******s 的大作中提到】 : stupid solution : select id from table where id = 1 union select id from table where id = 2 : union select id from table where id = 5 union .....
|
|