{"id":200588,"date":"2025-05-06T09:05:51","date_gmt":"2025-05-06T01:05:51","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200588\/"},"modified":"2025-05-06T09:05:51","modified_gmt":"2025-05-06T01:05:51","slug":"%e5%a6%82%e4%bd%95%e7%94%a8%e7%b4%a2%e5%bc%95%e8%a1%a8%e4%bc%98%e5%8c%96-mysql-%e5%8d%83%e4%b8%87%e7%ba%a7%e6%95%b0%e6%8d%ae%e7%9a%84%e6%a8%a1%e7%b3%8a%e6%90%9c%e7%b4%a2%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200588\/","title":{"rendered":"\u5982\u4f55\u7528\u7d22\u5f15\u8868\u4f18\u5316 MySQL \u5343\u4e07\u7ea7\u6570\u636e\u7684\u6a21\u7cca\u641c\u7d22\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5982\u4f55\u7528\u7d22\u5f15\u8868\u4f18\u5316 MySQL \u5343\u4e07\u7ea7\u6570\u636e\u7684\u6a21\u7cca\u641c\u7d22\uff1f<\/h1>\n<p>\u201c\u7eb5\u6709\u75be\u98ce\u6765\uff0c\u4eba\u751f\u4e0d\u8a00\u5f03\u201d\uff0c\u8fd9\u53e5\u8bdd\u9001\u7ed9\u6b63\u5728\u5b66\u4e60\u7684\u670b\u53cb\u4eec\uff0c\u4e5f\u5e0c\u671b\u5728\u9605\u8bfb\u672c\u6587\u540e\uff0c\u80fd\u591f\u771f\u7684\u5e2e\u52a9\u5230\u5927\u5bb6\u3002\u6211\u4e5f\u4f1a\u5728\u540e\u7eed\u7684\u6587\u7ae0\u4e2d\uff0c\u9646\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u6280\u672f\u6587\u7ae0\uff0c\u6709\u597d\u7684\u5efa\u8bae\u6b22\u8fce\u5927\u5bb6\u5728\u8bc4\u8bba\u7559\u8a00\uff0c\u975e\u5e38\u611f\u8c22\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241109\/1731118545672ec5d182d37.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u5982\u4f55\u4f18\u5316 mysql \u5343\u4e07\u6570\u636e\u91cf\u7684\u6a21\u7cca\u641c\u7d22<\/strong><\/p>\n<p>\u5bf9\u4e8e\u5305\u542b\u5343\u4e07\u6570\u636e\u91cf\u7684 mysql \u6570\u636e\u5e93\u4e2d\u6a21\u7cca\u641c\u7d22\u7684\u6027\u80fd\u4f18\u5316\uff0c\u4e00\u4e2a\u7b80\u5355\u7684\u60f3\u6cd5\u662f\u521b\u5efa\u7c7b\u4f3c\u4e0b\u8868\u7684\u7d22\u5f15\uff1a<\/p>\n<pre>\u7d22\u5f15\u8868\n\n| \u5f53\u524d\u8bcd | \u4e0b\u4e00\u8bcd | \u539f\u8bb0\u5f55\u4e3b\u952e id |\n|---|---|---|\n| mysql | \u4e00 | 1 |\n| \u4e00 | \u5343 | 1 |\n| \u5343 | \u4e07 | 1 |\n| \u4e07 | \u7684 | 1 |\n| ... | ... | ... |\n| \u6a21 | \u7cca | 1 |\n| \u7cca | \u641c | 1 |\n| \u641c | \u7d22 | 1 |\n| \u7d22 | null | 1 |<\/pre>\n<p>\u4ee5\u6b64\u65b9\u5f0f\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u8be5\u7d22\u5f15\u8868\u4e2d\u9ad8\u6548\u5730\u641c\u7d22\u201c\u6a21\u7cca\u641c\u7d22\u201d\uff0c\u4f7f\u7528\u5982\u4e0b sql \u67e5\u8be2\uff1a<\/p>\n<pre>SELECT \u539f\u8bb0\u5f55\u4e3b\u952eID\nFROM (SELECT \u539f\u8bb0\u5f55\u4e3b\u952eID FROM \u7d22\u5f15\u8868 WHERE \u5f53\u524d\u8bcd = '\u6a21' AND \u4e0b\u4e00\u8bcd = '\u7cca')\nJOIN (SELECT \u539f\u8bb0\u5f55\u4e3b\u952eID FROM \u7d22\u5f15\u8868 WHERE \u5f53\u524d\u8bcd = '\u7cca' AND \u4e0b\u4e00\u8bcd = '\u641c') USING(\u539f\u8bb0\u5f55\u4e3b\u952eID)\nJOIN (SELECT \u539f\u8bb0\u5f55\u4e3b\u952eID FROM \u7d22\u5f15\u8868 WHERE \u5f53\u524d\u8bcd = '\u641c' AND \u4e0b\u4e00\u8bcd = '\u7d22') USING(\u539f\u8bb0\u5f55\u4e3b\u952eID)\nJOIN (SELECT \u539f\u8bb0\u5f55\u4e3b\u952eID FROM \u7d22\u5f15\u8868 WHERE \u5f53\u524d\u8bcd = '\u7d22' AND \u4e0b\u4e00\u8bcd IS NULL) USING(\u539f\u8bb0\u5f55\u4e3b\u952eID)<\/pre>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u6709\u6548\u5730\u7f29\u5c0f\u641c\u7d22\u8303\u56f4\uff0c\u4ece\u800c\u63d0\u9ad8\u6a21\u7cca\u641c\u7d22\u7684\u6027\u80fd\uff0c\u5728\u79d2\u7ea7\u5185\u5b8c\u6210\u641c\u7d22\u3002<\/p>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300a\u5982\u4f55\u7528\u7d22\u5f15\u8868\u4f18\u5316 MySQL \u5343\u4e07\u7ea7\u6570\u636e\u7684\u6a21\u7cca\u641c\u7d22\uff1f\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u7528\u7d22\u5f15\u8868\u4f18\u5316 MySQL \u5343&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-200588","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200588","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=200588"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200588\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200588"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200588"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200588"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}