{"id":4153,"date":"2023-11-06T09:52:23","date_gmt":"2023-11-06T01:52:23","guid":{"rendered":"https:\/\/white-night.club\/?p=4153"},"modified":"2023-11-09T11:07:42","modified_gmt":"2023-11-09T03:07:42","slug":"ad132","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/11\/06\/ad132\/","title":{"rendered":"1421.\u00a0\u51c0\u73b0\u503c\u67e5\u8be2"},"content":{"rendered":"\n<p>\u8868:&nbsp;<code>NPV<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| year          | int     |\n| npv           | int     |\n+---------------+---------+\n(id, year) \u662f\u8be5\u8868\u4e3b\u952e(\u5177\u6709\u552f\u4e00\u503c\u7684\u5217\u7684\u7ec4\u5408).\n\u8be5\u8868\u6709\u6bcf\u4e00\u7b14\u5b58\u8d27\u7684\u5e74\u4efd, id \u548c\u5bf9\u5e94\u51c0\u73b0\u503c\u7684\u4fe1\u606f.\n<\/pre>\n\n\n\n<p>\u8868:&nbsp;<code>Queries<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| year          | int     |\n+---------------+---------+\n(id, year) \u662f\u8be5\u8868\u4e3b\u952e(\u5177\u6709\u552f\u4e00\u503c\u7684\u5217\u7684\u7ec4\u5408).\n\u8be5\u8868\u6709\u6bcf\u4e00\u6b21\u67e5\u8be2\u6240\u5bf9\u5e94\u5b58\u8d27\u7684 id \u548c\u5e74\u4efd\u7684\u4fe1\u606f.\n<\/pre>\n\n\n\n<p>\u7f16\u5199\u89e3\u51b3\u65b9\u6848\uff0c\u627e\u5230 Queries&nbsp;\u8868\u4e2d\u6bcf\u4e00\u6b21\u67e5\u8be2\u7684\u51c0\u73b0\u503c\u3002<\/p>\n\n\n\n<p>\u7ed3\u679c\u8868&nbsp;<strong>\u6ca1\u6709\u987a\u5e8f\u8981\u6c42&nbsp;<\/strong>\u3002<\/p>\n\n\n\n<p>\u67e5\u8be2\u7ed3\u679c\u7684\u683c\u5f0f\u5982\u4e0b\u6240\u793a:<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>\nNPV \u8868:\n+------+--------+--------+\n| id   | year   | npv    |\n+------+--------+--------+\n| 1    | 2018   | 100    |\n| 7    | 2020   | 30     |\n| 13   | 2019   | 40     |\n| 1    | 2019   | 113    |\n| 2    | 2008   | 121    |\n| 3    | 2009   | 12     |\n| 11   | 2020   | 99     |\n| 7    | 2019   | 0      |\n+------+--------+--------+\n\nQueries \u8868:\n+------+--------+\n| id   | year   |\n+------+--------+\n| 1    | 2019   |\n| 2    | 2008   |\n| 3    | 2009   |\n| 7    | 2018   |\n| 7    | 2019   |\n| 7    | 2020   |\n| 13   | 2019   |\n+------+--------+\n<strong>\u8f93\u51fa\uff1a<\/strong>\n+------+--------+--------+\n| id   | year   | npv    |\n+------+--------+--------+\n| 1    | 2019   | 113    |\n| 2    | 2008   | 121    |\n| 3    | 2009   | 12     |\n| 7    | 2018   | 0      |\n| 7    | 2019   | 0      |\n| 7    | 2020   | 30     |\n| 13   | 2019   | 40     |\n+------+--------+--------+\n<strong>\u89e3\u91ca\uff1a<\/strong>\n(7, 2018)\u7684\u51c0\u73b0\u503c\u4e0d\u5728 NPV \u8868\u4e2d, \u6211\u4eec\u628a\u5b83\u770b\u4f5c\u662f 0.\n\u6240\u6709\u5176\u5b83\u67e5\u8be2\u7684\u51c0\u73b0\u503c\u90fd\u80fd\u5728 NPV \u8868\u4e2d\u627e\u5230.<\/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<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u8c01LEFT JOIN\u8c01\uff0c\u5982\u679cA\u7684\u8bb0\u5f55\u5728B\u4e2d\u90fd\u80fd\u5339\u914d\u7684\u4e0a\uff0c\u90a3\u4e48\u5c31\u5e94\u8be5\u662fB LEFT JOIN A\u3002\u4e3a\u4ec0\u4e48\u4e0d\u662fA LEFT JOIN B\u5462\uff1f\u56e0\u4e3a\u8fd9\u610f\u5473\u7740B\u6240\u8868\u793a\u7684\u8303\u56f4\u6bd4A\u66f4\u5927\uff0cB\u4e2d\u6709\u90e8\u5206\u8bb0\u5f55\u65e0\u6cd5\u5728A\u4e2d\u627e\u5230\u5339\u914d\u7684\u8bb0\u5f55\uff0c\u6240\u4ee5\u8fd9\u90e8\u5206\u627e\u4e0d\u5230\u7684\u8bb0\u5f55\u6700\u540e\u4f1a\u8fd4\u56deNULL\uff0c\u63a5\u4e0b\u6765\u7528IFNULL\u8bbe\u521d\u503c\u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Write your MySQL query statement below\r\nSELECT A.id,A.year,IFNULL(B.npv,0) AS npv\r\nFROM Queries AS A \r\nLEFT JOIN NPV AS B \r\nON A.id=B.id AND A.year=B.year<\/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\/4153"}],"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=4153"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/4153\/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=4153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=4153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=4153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}