{"id":7192,"date":"2024-11-14T15:21:12","date_gmt":"2024-11-14T07:21:12","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7192\/"},"modified":"2024-11-14T15:21:12","modified_gmt":"2024-11-14T07:21:12","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-mysql-%e5%85%b3%e8%81%94%e8%a1%a8%e6%9f%a5%e8%af%a2%ef%bc%8c%e7%ad%9b%e9%80%89%e5%87%ba%e4%b8%a4%e7%a7%8d%e4%b8%8d%e5%90%8c%e5%85%b3%e8%81%94%e5%85%b3%e7%b3%bb","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7192\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 MySQL \u5173\u8054\u8868\u67e5\u8be2\uff0c\u7b5b\u9009\u51fa\u4e24\u79cd\u4e0d\u540c\u5173\u8054\u5173\u7cfb\u7684\u6570\u636e\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173060381572237.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 MySQL \u5173\u8054\u8868\u67e5\u8be2\uff0c\u7b5b\u9009\u51fa\u4e24\u79cd\u4e0d\u540c\u5173\u8054\u5173\u7cfb\u7684\u6570\u636e\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 MySQL \u5173\u8054\u8868\u67e5\u8be2\uff0c\u7b5b\u9009\u51fa\u4e24\u79cd\u4e0d\u540c\u5173\u8054\u5173\u7cfb\u7684\u6570\u636e\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong> \u5173\u8054\u8868\u67e5\u8be2\u2014\u2014\u67e5\u8be2\u4e24\u79cd\u5173\u8054\u6570\u636e<\/strong><\/p>\n<p>\u7ed9\u5b9a\u4e24\u4e2a\u8868 a \u548c b\uff0ca \u8868\u5305\u542b outer_id \u5217\uff0c\u800c b \u8868\u5305\u542b type \u5217\u3002\u76ee\u6807\u662f\u67e5\u8be2 a \u8868\u4e2d\u7684\u4e24\u7c7b\u6570\u636e\uff1a<\/p>\n<ol>\n<li>\u5728 a \u8868\u4e2d\u4e0d\u5b58\u5728\u4e8e b \u8868\u7684 outer_id\uff0c\u6216\u8005\u5b58\u5728\u4e8e b \u8868\u4f46 type \u4e0d\u7b49\u4e8e 99\u3002<\/li>\n<li>\u5b58\u5728\u4e8e b \u8868\u4e14 type \u7b49\u4e8e 99 \u7684 a \u8868\u6570\u636e\u3002<\/li>\n<\/ol>\n<p><strong>\u7b2c\u4e00\u7c7b\u6570\u636e<\/strong><\/p>\n<p>\u8981\u67e5\u8be2\u7b2c\u4e00\u7c7b\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u8bed\u53e5\uff1a<\/p>\n<pre>select a.*\nfrom a a\nleft join b b on b.id = a.outer_id\nwhere b.id is null\n   or (b.id is not null and b.type != 99)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u8bed\u53e5\u4f7f\u7528\u5de6\u8fde\u63a5\uff0c\u5b83\u4f1a\u5c06 a \u8868\u4e2d\u7684\u6240\u6709\u884c\u90fd\u8fd4\u56de\uff0c\u5373\u4f7f\u5728 b \u8868\u4e2d\u6ca1\u6709\u5339\u914d\u7684\u8bb0\u5f55\u3002where \u5b50\u53e5\u7528\u4e8e\u8fc7\u6ee4\u6389\u4e0d\u5b58\u5728\u4e8e b \u8868\u4e2d\u6216 type \u4e0d\u7b49\u4e8e 99 \u7684\u884c\u3002<\/p>\n<p><strong>\u7b2c\u4e8c\u7c7b\u6570\u636e<\/strong><\/p>\n<p>\u8981\u67e5\u8be2\u7b2c\u4e8c\u7c7b\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u8bed\u53e5\uff1a<\/p>\n<pre>SELECT a.*\nFROM A a\nINNER JOIN B b ON b.id = a.outer_id AND b.type = 99<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u8bed\u53e5\u4f7f\u7528\u5185\u8fde\u63a5\uff0c\u5b83\u53ea\u4f1a\u8fd4\u56de a \u8868\u4e2d\u5b58\u5728\u4e8e b \u8868\u4e2d\u4e14 type \u7b49\u4e8e 99 \u7684\u884c\u3002where \u5b50\u53e5\u7528\u4e8e\u6307\u5b9a\u8fd9\u4e9b\u6761\u4ef6\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 MySQL \u5173\u8054\u8868\u67e5\u8be2\uff0c\u7b5b\u9009\u51fa\u4e24\u79cd\u4e0d\u540c\u5173\u8054\u5173\u7cfb\u7684\u6570\u636e\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5173\u8054\u8868\u67e5\u8be2\u2014\u2014\u67e5\u8be2\u4e24\u79cd\u5173\u8054\u6570\u636e \u7ed9\u5b9a\u4e24\u4e2a\u8868 a \u548c b\uff0ca \u8868\u5305\u542b outer_id \u5217\uff0c\u800c b \u8868\u5305\u542b type \u5217\u3002\u76ee\u6807\u662f\u67e5\u8be2 a \u8868\u4e2d\u7684\u4e24\u7c7b\u6570\u636e\uff1a \u5728 a \u8868\u4e2d\u4e0d\u5b58\u5728\u4e8e b \u8868\u7684 outer_id\uff0c\u6216\u8005\u5b58\u5728\u4e8e b \u8868\u4f46 type \u4e0d\u7b49\u4e8e 99\u3002 \u5b58\u5728\u4e8e b \u8868\u4e14 type \u7b49\u4e8e 99 \u7684 a \u8868\u6570\u636e\u3002 \u7b2c\u4e00\u7c7b\u6570\u636e \u8981\u67e5\u8be2\u7b2c\u4e00\u7c7b\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u8bed\u53e5\uff1a select a.* from a a left join b b on b.id = a.outer_id where b.id is null or (b.id [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-7192","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7192","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=7192"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7192\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}