{"id":4865,"date":"2023-11-12T13:20:06","date_gmt":"2023-11-12T05:20:06","guid":{"rendered":"https:\/\/white-night.club\/?p=4865"},"modified":"2023-11-12T13:41:06","modified_gmt":"2023-11-12T05:41:06","slug":"ad147","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/11\/12\/ad147\/","title":{"rendered":"1398.\u00a0\u8d2d\u4e70\u4e86\u4ea7\u54c1 A \u548c\u4ea7\u54c1 B \u5374\u6ca1\u6709\u8d2d\u4e70\u4ea7\u54c1 C \u7684\u987e\u5ba2"},"content":{"rendered":"\n<p><code>Customers<\/code>\u00a0\u8868\uff1a+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+ | Column Name | Type | +&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+ | customer_id | int | | customer_name | varchar | +&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+ customer_id \u662f\u8fd9\u5f20\u8868\u4e2d\u5177\u6709\u552f\u4e00\u503c\u7684\u5217\u3002 customer_name \u662f\u987e\u5ba2\u7684\u540d\u79f0\u3002<\/p>\n\n\n\n<p><code>Orders<\/code>&nbsp;\u8868\uff1a+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+ | Column Name | Type | +&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+ | order_id | int | | customer_id | int | | product_name | varchar | +&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;+ order_id \u662f\u8fd9\u5f20\u8868\u4e2d\u5177\u6709\u552f\u4e00\u503c\u7684\u5217\u3002 customer_id \u662f\u8d2d\u4e70\u4e86\u540d\u4e3a &#8220;product_name&#8221; \u4ea7\u54c1\u987e\u5ba2\u7684id\u3002<\/p>\n\n\n\n<p>\u8bf7\u4f60\u7f16\u5199\u89e3\u51b3\u65b9\u6848\uff0c\u62a5\u544a\u8d2d\u4e70\u4e86\u4ea7\u54c1&nbsp;<strong>&#8220;A&#8221;<\/strong>\uff0c<strong>&#8220;B&#8221;<\/strong>&nbsp;\u4f46\u6ca1\u6709\u8d2d\u4e70\u4ea7\u54c1&nbsp;<strong>&#8220;C&#8221;<\/strong>&nbsp;\u7684\u5ba2\u6237\u7684 customer_id \u548c customer_name\uff0c\u56e0\u4e3a\u6211\u4eec\u60f3\u63a8\u8350\u4ed6\u4eec\u8d2d\u4e70\u8fd9\u6837\u7684\u4ea7\u54c1\u3002<\/p>\n\n\n\n<p>\u8fd4\u56de\u6309&nbsp;<code>customer_id<\/code>&nbsp;<strong>\u6392\u5e8f<\/strong>&nbsp;\u7684\u7ed3\u679c\u8868\u3002<\/p>\n\n\n\n<p>\u8fd4\u56de\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><strong>\u8f93\u5165\uff1a<\/strong> Customers table: +&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;+ | customer_id | customer_name | +&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;+ | 1 | Daniel | | 2 | Diana | | 3 | Elizabeth | | 4 | Jhon | +&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;+ Orders table: +&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;+ | order_id | customer_id | product_name | +&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;+ | 10 | 1 | A | | 20 | 1 | B | | 30 | 1 | D | | 40 | 1 | C | | 50 | 2 | A | | 60 | 3 | A | | 70 | 3 | B | | 80 | 3 | D | | 90 | 4 | C | +&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;+ <strong>\u8f93\u51fa\uff1a<\/strong> +&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;+ | customer_id | customer_name | +&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;+ | 3 | Elizabeth | +&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;+ <strong>\u89e3\u91ca\uff1a<\/strong> \u53ea\u6709 customer_id \u4e3a 3 \u7684\u987e\u5ba2\u8d2d\u4e70\u4e86\u4ea7\u54c1 A \u548c\u4ea7\u54c1 B \uff0c\u5374\u6ca1\u6709\u8d2d\u4e70\u4ea7\u54c1 C \u3002<\/p>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color has-link-color wp-elements-b732731d734325b0e1d438f8ea50a1ce\">\n<p>\u89e3\u9898\u601d\u8def<\/p>\n<cite><em>LEFT JOIN+JOIN<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u8bf4\u5b9e\u8bdd\u6211\u662f\u4e0b\u610f\u8bc6\u5730\u60f3\u5230\u7528JOIN\uff0c\u81f3\u4e8e\u4e3a\u4ec0\u4e48\u6211\u8fd8\u771f\u4e0d\u77e5\u9053\u3002<\/p>\n\n\n\n<p>\u4e70\u4e86A\u548cB\uff0c\u8bf4\u660eLEFT JOIN\u7684\u65f6\u5019\u80fd\u627e\u5230\u3002\u6ca1\u4e70C\uff0c\u8bf4\u660eLEFT JOIN\u7684\u65f6\u5019\u4e3aNULL\u3002\u90a3\u4e48\u5148JOIN\u627e\u51fa\u4e70\u4e86A\u548cB\u7684\u4eba\uff0c\u518dLEFT JOIN\u770b\u770b\u8c01\u6ca1\u4e70C\uff0c\u8fd8\u662f\u633a\u7b80\u5355\u7684\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Write your MySQL query statement below\r\nSELECT DISTINCT A.customer_id,A.customer_name\r\nFROM Customers AS A \r\nJOIN Orders AS B \r\nON A.customer_id=B.customer_id AND B.product_name='A'\r\nJOIN Orders AS C\r\nON A.customer_id=C.customer_id AND C.product_name='B'\r\nLEFT JOIN Orders AS D \r\nON A.customer_id=D.customer_id AND D.product_name='C'\r\nWHERE D.product_name IS NULL<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1a\u81ea\u8054\u7ed3+\u5de6\u8054\u7ed3<\/p>\n","protected":false},"author":1,"featured_media":2827,"comment_status":"open","ping_status":"","sticky":false,"template":"base","format":"standard","meta":{"footnotes":""},"categories":[42,25],"tags":[38],"_links":{"self":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/4865"}],"collection":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/comments?post=4865"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/4865\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/2827"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=4865"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=4865"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=4865"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}