MySQL Field排序法

技术分享
检索 id = 2 or id = 5 or id = 9 or id = 56 or id = 38.
然后按照 2 , 5, 9, 56, 38 这个顺序排列,这是题目要求
 
以下为解决方案:
1.SELECT * FROM `test` WHERE `id` IN(2,5,9,56,38) ORDER BY FIELD(`id`,2,5,9,56,38); (方案出自:http://www.phptext.net/article_view.php?id=199)
2.select * case `id` when 38 then 57 else `id` end as myorder from test where find_in_set(`id`,2,5,9,56,38) order by myorder
3.(此种不是很明白)
(SELECT * FROM `account_biz` where  id = 2)
UNION (select * from account_biz where   id = 5)
UNION (select * from account_biz where   id = 9)
UNION (SELECT * FROM `account_biz` where  id = 56)
UNION (select * from account_biz where   id = 38);
 
 
 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。