可能我说的意思有点含糊了.
原表
table:
id ...
------
...
8 ...
9 ...
10 ...
11 ...
12 ...
13 ...
14 ...
15 ...
16 ...
17 ...
...
21 ...
...在执行select * from table where id in (8,21,11,14,17)后
我得到的结果是
table:
id ...
------
8
11
14
17
21
我想得到的结果是(按in里的顺序排列):
table:
id ...
------
8
21
11
14
17
原表
table:
id ...
------
...
8 ...
9 ...
10 ...
11 ...
12 ...
13 ...
14 ...
15 ...
16 ...
17 ...
...
21 ...
...在执行select * from table where id in (8,21,11,14,17)后
我得到的结果是
table:
id ...
------
8
11
14
17
21
我想得到的结果是(按in里的顺序排列):
table:
id ...
------
8
21
11
14
17
如支持:
select * from tt where id in (8,21,11,14,17)
order by iif(id=8,1,iif(id=21,2,iif(id=11,3,iif(id=14,4,5))))
序号 ID
1 8
2 21
3 11
4 14
5 17
然后用表关联,如:
select A.*
from 你的表名 as A
inner join 临时表 AS B on A.ID=b.ID
order by B.序号
union
select * from `table` where id=21
union
select * from `table` where id=11
union
select * from `table` where id=14
union
select * from `table` where id=17存储过程也可以拼语句,只不过传参麻烦。