本文共 526 字,大约阅读时间需要 1 分钟。
mysql使in、find_in_set按顺序查出来
select * from table_name where id in ()或者select * from table_name where find_in_set()的时候,MySQL会自动按主键自增排序,要是按给定的顺序来取,如何实现呢?
1、使in按顺序查出来select ID from IndexData where Type=2 and RelateID in(2,4,1,3) order by FIND_IN_SET(RelateID,'2,4,1,3');
2、使find_in_set按顺序查出来select ID from IndexData where Type=2 and FIND_IN_SET(RelateID,'2,4,1,3') order by FIND_IN_SET(RelateID,'2,4,1,3');
find_in_set实现 1,2,3 查询 3,6,11(departure字段)
(FIND_IN_SET(1,departure) or FIND_IN_SET(2,departure) or FIND_IN_SET(3,departure)
转载地址:http://xmltx.baihongyu.com/