{"id":3336,"date":"2023-10-25T19:26:26","date_gmt":"2023-10-25T11:26:26","guid":{"rendered":"https:\/\/white-night.club\/?p=3336"},"modified":"2023-11-09T11:07:46","modified_gmt":"2023-11-09T03:07:46","slug":"db12","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/10\/25\/db12\/","title":{"rendered":"MySQL:IFNULL\u65e0\u6cd5\u8fd4\u56denull\u7684\u60c5\u51b5"},"content":{"rendered":"\n<p>\u4e3a\u4ec0\u4e48\u5f53exp\u4e3a\u201d\u7a7a\u201c\u65f6\uff0cIFNULL(exp,null)\u65e0\u6cd5\u8fd4\u56denull\uff1f<\/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\">\n<p>\u524d\u60c5\u63d0\u8981<\/p>\n<cite><em>\u4ec0\u4e48\u60c5\u666f\u4e0b\u4f1a\u53d1\u751f\u8be5\u95ee\u9898<\/em><\/cite><\/blockquote>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/leetcode.cn\/problems\/biggest-single-number\/description\/\" data-type=\"URL\" data-id=\"https:\/\/leetcode.cn\/problems\/biggest-single-number\/description\/\" target=\"_blank\"><mark style=\"background-color:rgba(0, 0, 0, 0);color:#0086ff\" class=\"has-inline-color\">\u6bd4\u5982\u6211\u4eec\u8981\u627e\u51fa\u4e00\u4e2a\u8868\u4e2d\u53ea\u51fa\u73b0\u8fc7\u4e00\u6b21\u7684\u6700\u5927\u6570\u5b57\u3002\u5982\u679c\u6ca1\u627e\u5230\u5219\u8fd4\u56deNULL(Leetcode\u9898\u76ee\uff09\u3002<\/mark><\/a> \u53c8\u6216\u8005\u662f\u627e\u51fa\u67d0\u4e2a\u4e0d\u7b49\u4e8e\u7279\u5b9a\u503c\u7684\u6570\uff0c\u8fd9\u4e2a\u65f6\u5019\u7528IFNULL\uff0c\u5f88\u5408\u7406\u4e5f\u5f88\u5bb9\u6613\u60f3\u5230\u3002<\/p>\n\n\n\n<p>\u6bd4\u5982\u6211\u4eec\u8981\u627e\u51fa\u4e0d\u7b49\u4e8e0\u7684\u6570\uff0c\u5982\u679c\u6ca1\u627e\u5230\u5c31\u8fd4\u56deNULL\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT IFNULL(num,null) AS num\nFROM MyNumbers\nWHERE num!=0<\/code><\/pre>\n\n\n\n<p>However\uff0c\u8fd9\u6761SQL\u6ca1\u7528\u3002\u4f60\u4f1a\u53d1\u73b0\u8fd4\u56de\u7684\u662f\u7a7a\u503c\uff08N\/A\uff09\uff0c\u800c\u4e0d\u662fnull\u3002\u8fd9\u91cc\u4e3a\u4e86\u65b9\u4fbf\u76f4\u63a5\u590d\u5236leetcode\u7684\u8f93\u51fa<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u8f93\u5165\nMyNumbers\u00a0=\n| num | \n| --- | \n| 0 |\n\n\u8f93\u51fa\n| num |\n| --- |<\/code><\/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\u91ca\u8bf4\u660e<\/p>\n<cite><em>\u628aNULL\u5f53\u7279\u6b8a\u503c\u770b<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u4e3a\u5565\u5462\uff1f\u5982\u679c\u8868\u4e2d\u7684\u6240\u6709\u6570\u90fd\u7b49\u4e8e0\uff0c\u90a3\u4e48\u6309\u7167SQL\u8bed\u53e5\u7684\u6267\u884c\u987a\u5e8f\uff0cFROM->WHERE->SELECT\uff0c\u5728WHERE\u7b5b\u9009\u540enum\u4e0d\u5c31\u4e3anull\u4e86\u5417\uff1f\u4e3a\u4ec0\u4e48IFNULL\u65e0\u6cd5\u8fd4\u56de\u540e\u503cnull\u5462\uff1f<\/p>\n\n\n\n<p>\u4e3a\u5565\u5728WHERE\u4e4b\u540e\u5c31\u4e0d\u751f\u6548\u4e86\uff1f\u5148\u601d\u8003\u4e00\u4e0b\uff0cWHERE\u7b5b\u9009\u4e4b\u540e\u7684\u7ed3\u679c\u96c6\u662fNULL\u5417\uff1f<\/p>\n\n\n\n<p><strong>\u5982\u662f\u3002\u5b83\u771f\u7684\u662fNULL\u5417\uff1f\u5982\u662f<\/strong>\u3002WHERE\u7b5b\u9009\u540e\u786e\u5b9e\u6ca1\u6709\u5339\u914d\u7684\u8bb0\u5f55\uff0c\u90a3\u5b83\u7684\u7ed3\u679c\u96c6\u91cc\u9762\u4f1a\u6709NULL\u5417\uff1f\u5f88\u660e\u663e\u4e0d\u4f1a\uff0c\u5355\u7eaf\u5c31\u662f\u5565\u90fd\u6ca1\u6709\uff0c\u5373<mark style=\"background-color:rgba(0, 0, 0, 0);color:#fcb900\" class=\"has-inline-color\">emptyset<\/mark>\uff0c\u7a7a\u503c\u7684\u96c6\u5408\u3002<\/p>\n\n\n\n<p>\u800cIFNULL\u662f\u5e72\u4ec0\u4e48\u7684\uff1f\u5bf9\u4e8eIFNULL(exp,value)\u6765\u8bf4\uff0c\u5f53exp\u7684\u7ed3\u679c\u4e3aNULL\uff0c\u624d\u4f1a\u8fd4\u56devalue\u3002\u800c\u4e0d\u662f\u5f53exp\u7684\u7ed3\u679c\u4e3a\u7a7a\u503c\uff08N\/A\uff09\u65f6\uff0c\u8fd4\u56devalue\u3002<\/p>\n\n\n\n<p>\u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u4e5f\u5f88\u7b80\u5355\uff0c\u52a0\u4e2a\u805a\u5408\u51fd\u6570\u5b8c\u4e8b\u3002\u6700\u76f4\u63a5\u7684\u5c31\u662f\u52a0\u4e2aMAX\uff0cMAX\u5bf9emptyset\u8ba1\u7b97\uff0c\u53d1\u73b0\u627e\u4e0d\u5230\u4efb\u4f55\u4e00\u6761\u8bb0\u5f55\uff0c\u8bf6\uff0c\u90a3\u5b83\u5c31\u8fd4\u56de\u4e2aNULL\uff0c\u5b8c\u4e8b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT IFNULL(MAX(num),null)AS num\r\nFROM MyNumbers\r\nWHERE num!=0<\/code><\/pre>\n\n\n\n<p>\u603b\u7684\u6765\u8bf4\u5c31\u662f\u628aNULL\u5f53\u4e00\u4e2a\u6bd4\u8f83\u7279\u6b8a\u7684\u503c\u6765\u770b\uff0c\u5982\u6b64\u5982\u6b64\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a\u4ec0\u4e48exp\u4e3a\u201c\u7a7a\u201d\u65f6\uff0cIFNULL\u65e0\u6cd5\u8fd4\u56deNULL\uff1f<\/p>\n","protected":false},"author":1,"featured_media":3123,"comment_status":"open","ping_status":"","sticky":false,"template":"base","format":"standard","meta":{"footnotes":""},"categories":[69,35],"tags":[99,80],"_links":{"self":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/3336"}],"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=3336"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/3336\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/3123"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=3336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=3336"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=3336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}