{"id":4974,"date":"2021-03-05T14:02:07","date_gmt":"2021-03-05T06:02:07","guid":{"rendered":"https:\/\/www.gbase8.cn\/?p=4974"},"modified":"2021-03-05T14:02:07","modified_gmt":"2021-03-05T06:02:07","slug":"gbase-8a%e4%b8%adnot-in-%e5%92%8c-not-exists%e7%9a%84%e5%8c%ba%e5%88%ab","status":"publish","type":"post","link":"https:\/\/www.gbase8.cn\/en\/4974","title":{"rendered":"\u5357\u5927\u901a\u7528GBase 8a\u4e2dnot in \u548c not exists\u7684\u533a\u522b"},"content":{"rendered":"<p>\u672c\u6587\u4ecb\u7ecd\uff0c\u5728GBase 8a\u6570\u636e\u636e\u96c6\u7fa4\u4e2d\uff0c not in \u548c not exists\u7684\u533a\u522b\u3002<\/p>\n\n\n\n<p>\u5148\u770bin \u548c exists\uff0c \u4ece\u672c\u8d28\u4e0a\u8bb2\uff0c\u90fd\u662f\u5224\u65ad\u7b49\u4e8e\uff0c\u8fd9\u4e2a\u57fa\u672c\u4e0d\u4f1a\u6709\u4efb\u4f55\u95ee\u9898\uff0c\u4f46\u5bf9\u4e8e\u5224\u65ad\u4e0d\u7b49\u4e8e\uff0c\u51fa\u73b0\u4e86\u4e00\u4e2a\u7279\u4f8b\uff0c\u90a3\u5c31\u662f null \u4e0d\u7b49\u4e8e\u4efb\u4f55\u503c\u3002<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Directory Navigation<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2ad31edaabc\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewbox=\"0 0 24 24\" version=\"1.2\" baseprofile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2ad31edaabc\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.gbase8.cn\/en\/4974\/#%E9%94%99%E8%AF%AF%E6%A0%B7%E4%BE%8B\" >\u9519\u8bef\u6837\u4f8b<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.gbase8.cn\/en\/4974\/#%E9%A2%9C%E8%89%B2%E8%A1%A8\" >\u989c\u8272\u8868<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.gbase8.cn\/en\/4974\/#%E4%BA%A7%E5%93%81%E8%A1%A8\" >\u4ea7\u54c1\u8868<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.gbase8.cn\/en\/4974\/#not_in%E7%9A%84%E6%9F%A5%E8%AF%A2%E7%BB%93%E6%9E%9C\" >not in\u7684\u67e5\u8be2\u7ed3\u679c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.gbase8.cn\/en\/4974\/#%E4%BF%AE%E6%AD%A3%E6%96%B9%E6%B3%95\" >\u4fee\u6b63\u65b9\u6cd5<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.gbase8.cn\/en\/4974\/#%E6%80%BB%E7%BB%93\" >Summary<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.gbase8.cn\/en\/4974\/#%E5%8F%82%E8%80%83\" >\u53c2\u8003<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E9%94%99%E8%AF%AF%E6%A0%B7%E4%BE%8B\"><\/span>\u9519\u8bef\u6837\u4f8b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u67e5\u8be2\u6ca1\u6709\u4f7f\u7528\u4e2d\u7684\u989c\u8272\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E9%A2%9C%E8%89%B2%E8%A1%A8\"><\/span>\u989c\u8272\u8868<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> select * from colors;\r\n+----------+-------------+\r\n| color_id | color_value |\r\n+----------+-------------+\r\n| c001     | Red         |\r\n| c002     | Yellow      |\r\n| c003     | Green       |\r\n| c004     | Black       |\r\n| c005     | White       |\r\n+----------+-------------+\r\n5 rows in set (Elapsed: 00:00:00.00)\r<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E4%BA%A7%E5%93%81%E8%A1%A8\"><\/span>\u4ea7\u54c1\u8868<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u6ce8\u610f\uff0c\u5176\u4e2d1003\u7684\u4ea7\u54c1\uff0c\u989c\u8272\u5f53\u524d\u672a\u77e5\uff0c\u4e3anull\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> select * from products;\r\n+------------+-------------------+----------+\r\n| product_id | product_name      | color_id |\r\n+------------+-------------------+----------+\r\n|       1000 | smartwatch        | c001     |\r\n|       1001 | ballpoint pen     | c003     |\r\n|       1002 | wireless keyboard | c004     |\r\n|       1003 | charging pad      | NULL     |\r\n+------------+-------------------+----------+\r\n4 rows in set (Elapsed: 00:00:00.01)\r\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"not_in%E7%9A%84%E6%9F%A5%E8%AF%A2%E7%BB%93%E6%9E%9C\"><\/span>not in\u7684\u67e5\u8be2\u7ed3\u679c<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u7ed3\u679c\u4e3a\u7a7a\uff0c\u4e0d\u662f\u9884\u671f\u7684Yellow\u548cWhite\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> SELECT col.color_value FROM Colors AS col \n  WHERE col.color_id  NOT IN  \n  (SELECT prod.color_id FROM Products AS prod);\r\nEmpty set (Elapsed: 00:00:00.04)\r\n\r\ngbase> <\/code><\/pre>\n\n\n\n<p>\u539f\u56e0\u5c31\u662f\uff0c\u5728\u5224\u65adnot in\u65f6\uff0c\u662f\u5c06\u6bcf\u4e2a\u503c\u505a\u7c7b\u4f3c\u5982\u4e0b\u7684\u5224\u65ad<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>color_id NOT IN (c001, c003, c004, NULL)<\/code><\/pre>\n\n\n\n<p>\u7b49\u540c\u4e8e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> NOT (color_id = c001 OR color_id = c003 OR color_id = c004 OR color_id = NULL).<\/code><\/pre>\n\n\n\n<p>\u800c\u5176\u4e2d\u7684 color_id = NULL \u5bfc\u81f4\u8fd4\u56de\u7ed3\u679c\u662f\u3010\u672a\u77e5\u3011\uff0c\u56e0\u4e3anull\u4e0d\u3010\u7b49\u4e8e\u3011null, \u4e5f\u4e0d\u3010\u4e0d\u7b49\u4e8e\u3011null\u3002<\/p>\n\n\n\n<p>\u6700\u7ec8\u5bfc\u81f4\u8fd4\u56de\u503c\u4e3afalse\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E4%BF%AE%E6%AD%A3%E6%96%B9%E6%B3%95\"><\/span> \u4fee\u6b63\u65b9\u6cd5<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u4f7f\u7528not exists\u4ee3\u66ffnot in ,\u9664\u975e\u4f60\u786e\u8ba4\u4f60\u7684\u6570\u636e\u91cc\u4e0d\u5305\u542bnull\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> SELECT col.color_value\r\n    -> FROM Colors AS col\r\n    -> WHERE NOT EXISTS\r\n    -> (SELECT prod.color_id\r\n    ->  FROM Products AS prod\r\n    ->  WHERE col.color_id = prod.color_id);\r\n+-------------+\r\n| color_value |\r\n+-------------+\r\n| Yellow      |\r\n| White       |\r\n+-------------+\r\n2 rows in set (Elapsed: 00:00:00.09)\r\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%80%BB%E7%BB%93\"><\/span>Summary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u5c3d\u91cf\u907f\u514d\u4f7f\u7528not in\u8fd9\u4e2a\u7528\u6cd5\uff0c\u800c\u662f\u6539\u7528not exists\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%8F%82%E8%80%83\"><\/span>\u53c2\u8003<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><a href=\"https:\/\/www.gbase8.cn\/en\/2518\/\">GBase 8a\u5728not in\u5b50\u67e5\u8be2\u4e2d\u6709null\u503c\u65f6\u8fd4\u56de\u7a7a\u7ed3\u679c\u96c6\u7684\u539f\u56e0<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>\u5357\u5927\u901a\u7528GBase 8a\u4e2dnot in \u548c not exists\u7684\u533a\u522b<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[54],"tags":[],"class_list":["post-4974","post","type-post","status-publish","format-standard","hentry","category-gbase8a"],"_links":{"self":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/4974","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/comments?post=4974"}],"version-history":[{"count":5,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/4974\/revisions"}],"predecessor-version":[{"id":4979,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/4974\/revisions\/4979"}],"wp:attachment":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/media?parent=4974"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/categories?post=4974"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/tags?post=4974"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}