{"id":368,"date":"2011-04-01T10:24:40","date_gmt":"2011-04-01T02:24:40","guid":{"rendered":"http:\/\/elon.852128.com\/blog\/?p=368"},"modified":"2011-04-01T10:24:40","modified_gmt":"2011-04-01T02:24:40","slug":"mysql-order-by-in-%e7%9a%84%e5%ad%97%e7%ac%a6%e9%a1%ba%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/elon.852128.com\/blog\/2011\/04\/01\/mysql-order-by-in-%e7%9a%84%e5%ad%97%e7%ac%a6%e9%a1%ba%e5%ba%8f\/","title":{"rendered":"mysql order by in \u7684\u5b57\u7b26\u987a\u5e8f"},"content":{"rendered":"<p>\u6709\u4e24\u79cd\u65b9\u5f0f\uff1a<\/p>\n<p>1. select uid from cdb where uid in (11,1,111) order by instr(&#8216;,11,1,111,&#8217;,concat(&#8216;,&#8217;,uid,&#8217;,&#8217;)) \u6ce8\u610f\u8981\u6784\u9020\u591a\u51fa\u7684, \u53f7<\/p>\n<p>2.\uff08\u63a8\u8350\uff09SELECT * FROM `cdb` WHERE `uid` IN (11,1,111) ORDER BY FIELD(`uid`, 11,1,111) <\/p>\n<p>\u6709\u6587\u7ae0\u6307\u51fa\uff1a<\/p>\n<p>FIELD(str,str1,str2,str3,&#8230;)<br \/>\nReturns the index (position) of str in the str1, str2, str3, &#8230; list. Returns 0 if str is not found.<\/p>\n<p>\u6392\u5e8f\u8fc7\u7a0b\uff1a\u628a\u9009\u51fa\u7684\u8bb0\u5f55\u7684 id \u5728 FIELD \u5217\u8868\u4e2d\u8fdb\u884c\u67e5\u627e\uff0c\u5e76\u8fd4\u56de\u4f4d\u7f6e\uff0c\u4ee5\u4f4d\u7f6e\u4f5c\u4e3a\u6392\u5e8f\u4f9d\u636e\u3002<\/p>\n<p>\u8fd9\u6837\u7684\u7528\u6cd5\uff0c\u4f1a\u5bfc\u81f4 Using filesort\uff0c\u662f\u6548\u7387\u5f88\u4f4e\u7684\u6392\u5e8f\u65b9\u5f0f\u3002\u9664\u975e\u6570\u636e\u53d8\u5316\u9891\u7387\u5f88\u4f4e\uff0c\u6216\u8005\u6709\u957f\u65f6\u95f4\u7684\u7f13\u5b58\uff0c\u5426\u5219\u4e0d\u5efa\u8bae\u7528\u8fd9\u6837\u7684\u65b9\u5f0f\u6392\u5e8f\u3002<\/p>\n<p>\u5efa\u8bae\u5728\u7a0b\u5e8f\u4ee3\u7801\u4e2d\u81ea\u884c\u6392\u5e8f\uff0c\u5b9e\u6d4b\u8fc7\u7a0b\u5f53\u4e2d\u6ca1\u53d1\u73b0\u6027\u80fd\u74f6\u9888\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u4e24\u79cd\u65b9\u5f0f\uff1a 1. select uid from cdb whe&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-368","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/elon.852128.com\/blog\/wp-json\/wp\/v2\/posts\/368","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elon.852128.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elon.852128.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elon.852128.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/elon.852128.com\/blog\/wp-json\/wp\/v2\/comments?post=368"}],"version-history":[{"count":1,"href":"https:\/\/elon.852128.com\/blog\/wp-json\/wp\/v2\/posts\/368\/revisions"}],"predecessor-version":[{"id":369,"href":"https:\/\/elon.852128.com\/blog\/wp-json\/wp\/v2\/posts\/368\/revisions\/369"}],"wp:attachment":[{"href":"https:\/\/elon.852128.com\/blog\/wp-json\/wp\/v2\/media?parent=368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elon.852128.com\/blog\/wp-json\/wp\/v2\/categories?post=368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elon.852128.com\/blog\/wp-json\/wp\/v2\/tags?post=368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}