{"id":163262,"date":"2020-10-03T18:05:55","date_gmt":"2020-10-03T10:05:55","guid":{"rendered":"http:\/\/4563.org\/?p=163262"},"modified":"2020-10-03T18:05:55","modified_gmt":"2020-10-03T10:05:55","slug":"%e6%b1%82%e4%b8%80%e4%b8%aa-sql-%e8%af%ad%e5%8f%a5%e6%88%96%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=163262","title":{"rendered":"\u6c42\u4e00\u4e2a sql \u8bed\u53e5\u6216\u89e3\u51b3\u529e\u6cd5"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u6c42\u4e00\u4e2a sql \u8bed\u53e5\u6216\u89e3\u51b3\u529e\u6cd5               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : mxm145 <\/span>  <span><i><\/i> 1<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u6709\u4e24\u4e2a\u8868 A\uff0cB \u3002A \u8868\u5b58\u7684\u6587\u7ae0\u6807\u9898\u3001\u53d1\u5e03\u65f6\u95f4\u8fd9\u4e9b\u4fe1\u606f\uff0cB \u8868\u5b58\u7684\u662f\u6587\u7ae0\u7684\u5185\u5bb9\uff0c\u4e24\u4e2a\u8868\u7684 ID \u662f\u4e00\u81f4\u7684\u3002\u73b0\u5728\u7684\u95ee\u9898\u662f\uff1a\u6709\u5173\u952e\u8bcd\u641c\u7d22\u7684\u65f6\u5019\u5148\u5728 A \u8868\u7684\u6807\u9898\u91cc\u9762\u8fdb\u884c\u641c\u7d22\uff0c\u518d\u5230 B \u8868\u7684\u6587\u7ae0\u5185\u5bb9\u5b57\u6bb5\u91cc\u9762\u8fdb\u884c\u641c\u7d22\uff0c\u6700\u540e\u8981\u628a\u4e24\u4e2a\u7ed3\u679c\u5408\u5e76\u8d77\u6765\u518d\u6309\u7167 A \u8868\u7684\u53d1\u5e03\u65f6\u95f4\u8fdb\u884c\u5012\u6392\u3002\u7528\u4e86 SQL \u7684 union \u641c\u7d22\uff0c\u5728\u6392\u5e8f\u7684\u65f6\u5019\u5c31\u4f1a\u628a\u4e24\u4e2a\u7ed3\u679c\u6df7\u5408\u5728\u4e00\u8d77\uff0c\u9700\u8981\u628a A \u8868\u7684\u641c\u7d22\u7ed3\u679c\u6309\u7167\u65f6\u95f4\u6392\u5e8f\u653e\u5728\u524d\u9762\uff0c\u4e0d\u77e5\u9053\u5404\u4f4d\u6709\u6ca1\u6709\u5565\u529e\u6cd5\u3002<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>8<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3561753\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : RedBeanIce <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u611f\u89c9\u5185\u5bb9\u641c\u7d22\uff0c\u6807\u9898\u641c\u7d22\uff0c\u5df2\u7ecf\u662f ES \uff1f\uff1f\uff1f\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3561754\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : LeeSeoung <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             A \u6392\u5e8f union all B \u6392\u5e8f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3561755\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : DonaldY <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u67e5\u8be2 sql \u65f6\uff0c\u591a\u52a0\u4e2a\u5b57\u6bb5\u6765\u6807\u8bc6\u6570\u636e\u6e90\u6765\u81ea\u54ea\uff0corder by \u8fd9\u4e2a\u5b57\u6bb5\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3561756\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jiorix <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             select aa.*<br \/>from<br \/>(<br \/> select a.*, 1 as queryType<br \/> from a <br \/> where title like &#8216;%\u5173\u952e\u5b57%&#8217;<br \/> union<br \/> select a.*, 2 as queryType<br \/> from a<br \/> where a.id in (<br \/> select id from b where content like &#8216;%\u5173\u952e\u5b57%&#8217;<br \/> )<br \/>) as aa<br \/>order by queryType, &#8230;.                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3561757\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : mxm145 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @RedBeanIce \u8fd8\u662f mysql\uff0c\u6ca1\u6709\u7528 es<br \/>@LeeSeoung \u6211\u67e5\u4e86 union \u6ca1\u529e\u6cd5\u7528\u4e24\u4e2a order<br \/>@jiorix \u591a\u8c22\u5927\u4f6c\u7684\u4ee3\u7801\uff0c\u601d\u8def\u6211\u61c2\u4e86<\/p>\n<p>\u591a\u8c22\u5404\u4f4d\u7684\u56de\u590d                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3561758\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : liuky <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             select a.*<br \/>from A as a<br \/>inner join B as b on a.id = b.id<br \/>where a.title like &#8216;%key%&#8217; and b.content like &#8216;%key%&#8217;<br \/>order by a.createtime desc                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3561759\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : mxm145 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @liuky \u8fd9\u4e2a\u8dd1\u51fa\u6765\u7684\u6570\u636e\u662f title \u548c content \u90fd\u6709\u5173\u952e\u8bcd\u7684\u7ed3\u679c\uff0c\u6211\u60f3\u8981\u7684\u662f\u53ea\u8981\u4e24\u4e2a\u5176\u4e2d\u4e00\u4e2a\u7684\u90fd\u8981\u663e\u793a\u51fa\u6765\uff0c\u800c\u4e14\u6309\u7167 title \u5339\u914d\u5230\u7684\u5728\u524d\u9762\uff0ccontent \u5339\u914d\u5230\u7684\u5728\u540e\u9762\u3002\u5982\u679c\u628a\u4f60\u7684 and \u6539\u6210 or \u7684\u8bdd\u4e5f\u4e0d\u884c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3561760\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : mxm145 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u6700\u540e\u4f7f\u7528\u7684\u662f\u4e24\u4e2a\u5b50\u67e5\u8be2 union \u6765\u5b9e\u73b0\u7684\uff0c\u53c2\u8003\u8fd9\u4e2a\uff1a https:\/\/www.jianshu.com\/p\/2a53c2fdb042                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u6c42\u4e00\u4e2a sql \u8bed\u53e5\u6216\u89e3\u51b3\u529e\u6cd5 \u8cc7&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/163262"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=163262"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/163262\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=163262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=163262"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=163262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}