{"id":2166,"date":"2023-10-08T10:34:24","date_gmt":"2023-10-08T02:34:24","guid":{"rendered":"https:\/\/white-night.club\/?p=2166"},"modified":"2023-11-09T11:07:51","modified_gmt":"2023-11-09T03:07:51","slug":"ad30","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/10\/08\/ad30\/","title":{"rendered":"175.&nbsp;\u7ec4\u5408\u4e24\u4e2a\u8868"},"content":{"rendered":"\n<p>\u8868:&nbsp;<code>Person<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+-------------+---------+\n| \u5217\u540d         | \u7c7b\u578b     |\n+-------------+---------+\n| PersonId    | int     |\n| FirstName   | varchar |\n| LastName    | varchar |\n+-------------+---------+\npersonId \u662f\u8be5\u8868\u7684\u4e3b\u952e\uff08\u5177\u6709\u552f\u4e00\u503c\u7684\u5217\uff09\u3002\n\u8be5\u8868\u5305\u542b\u4e00\u4e9b\u4eba\u7684 ID \u548c\u4ed6\u4eec\u7684\u59d3\u548c\u540d\u7684\u4fe1\u606f\u3002\n<\/pre>\n\n\n\n<p>\u8868:&nbsp;<code>Address<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+-------------+---------+\n| \u5217\u540d         | \u7c7b\u578b    |\n+-------------+---------+\n| AddressId   | int     |\n| PersonId    | int     |\n| City        | varchar |\n| State       | varchar |\n+-------------+---------+\naddressId \u662f\u8be5\u8868\u7684\u4e3b\u952e\uff08\u5177\u6709\u552f\u4e00\u503c\u7684\u5217\uff09\u3002\n\u8be5\u8868\u7684\u6bcf\u4e00\u884c\u90fd\u5305\u542b\u4e00\u4e2a ID = PersonId \u7684\u4eba\u7684\u57ce\u5e02\u548c\u5dde\u7684\u4fe1\u606f\u3002\n<\/pre>\n\n\n\n<p>\u7f16\u5199\u89e3\u51b3\u65b9\u6848\uff0c\u62a5\u544a&nbsp;<code>Person<\/code>&nbsp;\u8868\u4e2d\u6bcf\u4e2a\u4eba\u7684\u59d3\u3001\u540d\u3001\u57ce\u5e02\u548c\u5dde\u3002\u5982\u679c&nbsp;<code>personId<\/code>&nbsp;\u7684\u5730\u5740\u4e0d\u5728&nbsp;<code>Address<\/code>&nbsp;\u8868\u4e2d\uff0c\u5219\u62a5\u544a\u4e3a&nbsp;<code>null<\/code>&nbsp;\u3002<\/p>\n\n\n\n<p>\u4ee5&nbsp;<strong>\u4efb\u610f\u987a\u5e8f<\/strong>&nbsp;\u8fd4\u56de\u7ed3\u679c\u8868\u3002<\/p>\n\n\n\n<p>\u7ed3\u679c\u683c\u5f0f\u5982\u4e0b\u6240\u793a\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165:<\/strong> \nPerson\u8868:\n+----------+----------+-----------+\n| personId | lastName | firstName |\n+----------+----------+-----------+\n| 1        | Wang     | Allen     |\n| 2        | Alice    | Bob       |\n+----------+----------+-----------+\nAddress\u8868:\n+-----------+----------+---------------+------------+\n| addressId | personId | city          | state      |\n+-----------+----------+---------------+------------+\n| 1         | 2        | New York City | New York   |\n| 2         | 3        | Leetcode      | California |\n+-----------+----------+---------------+------------+\n<strong>\u8f93\u51fa:<\/strong> \n+-----------+----------+---------------+----------+\n| firstName | lastName | city          | state    |\n+-----------+----------+---------------+----------+\n| Allen     | Wang     | Null          | Null     |\n| Bob       | Alice    | New York City | New York |\n+-----------+----------+---------------+----------+\n<strong>\u89e3\u91ca:<\/strong> \n\u5730\u5740\u8868\u4e2d\u6ca1\u6709 personId = 1 \u7684\u5730\u5740\uff0c\u6240\u4ee5\u5b83\u4eec\u7684\u57ce\u5e02\u548c\u5dde\u8fd4\u56de null\u3002\naddressId = 1 \u5305\u542b\u4e86 personId = 2 \u7684\u5730\u5740\u4fe1\u606f\u3002<\/pre>\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\">\n<p>\u89e3\u9898\u601d\u8def<\/p>\n<cite><em>LEFT JOIN\u7684\u7528\u6cd5<\/em><\/cite><\/blockquote>\n\n\n\n<p>LEFT JOIN\uff0c\u987e\u540d\u601d\u4e49\uff0c\u65e0\u8bba\u5982\u4f55\u90fd\u4f1a\u4ece\u5de6\u8868\u8fd4\u56de\u6240\u6709\u7684\u884c\uff0c\u8ddf\u5728left join\u540e\u9762\u7684\u8868\uff0c\u5982\u679c\u4e0d\u6ee1\u8db3ON\u7684\u6761\u4ef6\uff0c\u90a3\u5c31\u8fd4\u56deNULL\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT column_name(s)\r\nFROM table1\r\nLEFT JOIN table2\r\nON table1.column_name=table2.column_name;<\/code><\/pre>\n\n\n\n<p>\u90a3\u5c31\u76f4\u63a5\u5957\u8fdb\u9898\u76ee\u5457\uff0c\u6ca1\u5565\u53ef\u8bb2\u7684\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Write your MySQL query statement below\r\nSELECT firstName,lastName,city,state FROM Person\r\nLEFT JOIN Address\r\nON Person.personId=Address.personId<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1aLEFT JOIN<\/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\/2166"}],"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=2166"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/2166\/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=2166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=2166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=2166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}