可能我说的意思有点含糊了.
原表
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
解决方案 »
- 如何用正则表达式判断一个字符串是另外一个字符串的的一部分
- 数据库错误,求指教。ERROR 1452 (23000): Cannot add or update a child row:
- mysql1.4 中的 mysqld-nd 使用内存不断增加 而winmysqladmin开起来后一会就死掉 请大家帮帮忙解决
- 求一sql语句
- 请教,在MySQL库中已知表名的情况下,如何取得这个表有多少个字段,字段名是什么?
- 为什么删不了东西?高手来看看
- 求一个mysql的自定义函数,中文字符串截取功能
- mysql截取问题
- 这条子查询如何改写为JOIN关联查询?
- C# MysQL用longblob字段存入二进制文件
- [急求]关于in排序 的问题!
- 关于mysql中left join的问题
如支持:
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存储过程也可以拼语句,只不过传参麻烦。