{"id":27718,"date":"2024-11-24T13:52:59","date_gmt":"2024-11-24T05:52:59","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27718\/"},"modified":"2024-11-24T13:52:59","modified_gmt":"2024-11-24T05:52:59","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-exists-%e5%85%b3%e9%94%ae%e5%ad%97%e5%88%a4%e6%96%ad%e4%b8%a4%e4%b8%aa%e8%a1%a8%e4%b8%ad%e6%98%af%e5%90%a6%e5%ad%98%e5%9c%a8%e7%9b%b8%e5%90%8c%e8%ae%b0%e5%bd%95-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27718\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 EXISTS \u5173\u952e\u5b57\u5224\u65ad\u4e24\u4e2a\u8868\u4e2d\u662f\u5426\u5b58\u5728\u76f8\u540c\u8bb0\u5f55\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173130840630329.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 EXISTS \u5173\u952e\u5b57\u5224\u65ad\u4e24\u4e2a\u8868\u4e2d\u662f\u5426\u5b58\u5728\u76f8\u540c\u8bb0\u5f55\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 EXISTS \u5173\u952e\u5b57\u5224\u65ad\u4e24\u4e2a\u8868\u4e2d\u662f\u5426\u5b58\u5728\u76f8\u540c\u8bb0\u5f55\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 exists \u5173\u952e\u5b57\u68c0\u67e5\u4e24\u4e2a\u8868\u4e2d\u662f\u5426\u5b58\u5728\u5bf9\u5e94\u7684\u503c\uff1f<\/strong><\/p>\n<p>\u8981\u627e\u51fa\u4e24\u4e2a\u8868\u4e2d\u662f\u5426\u5b58\u5728\u5bf9\u5e94\u7684\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528 exists \u5173\u952e\u5b57\u3002\u6b64\u5173\u952e\u5b57\u68c0\u67e5\u4e00\u4e2a\u5b50\u67e5\u8be2\u662f\u5426\u8fd4\u56de\u4efb\u4f55\u884c\uff0c\u5982\u679c\u8fd4\u56de\uff0c\u5219 exists \u8fd4\u56de true\uff1b\u5426\u5219\uff0c\u8fd4\u56de false\u3002<\/p>\n<p><strong>\u793a\u4f8b\u67e5\u8be2\uff1a<\/strong><\/p>\n<p>\u4ee5\u4e0b\u67e5\u8be2\u4f7f\u7528 exists \u68c0\u67e5\u540d\u4e3a temp1 \u7684\u8868\u7684\u884c\u662f\u5426\u51fa\u73b0\u5728\u540d\u4e3a temp2 \u7684\u8868\u4e2d\uff1a<\/p>\n<pre>select *\nfrom temp1\nwhere exists (\n    select *\n    from temp2\n    where temp1.pn_code = temp2.pn_code\n    and temp1.serialnumber = temp2.serialnumber\n);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u4fee\u6539\u540e\u7684\u67e5\u8be2\uff1a<\/strong><\/p>\n<p>\u5728\u4f60\u7684\u60c5\u51b5\u4e0b\uff0c\u4f60\u9700\u8981\u68c0\u67e5\u4e3b\u8868\uff08temp1\uff09\u4e2d\u7684\u884c\u662f\u5426\u51fa\u73b0\u5728\u5b50\u8868\uff08temp2\uff09\u4e2d\u3002\u4fee\u6539\u540e\u7684\u67e5\u8be2\u5982\u4e0b\uff1a<\/p>\n<pre>SELECT *\nFROM (\n    SELECT pn_Code, serialNumber\n    FROM pnassertbasic_ruku pr\n    LEFT JOIN pnassertruku pu ON pr.parent_pnAssertRuku_id = pu.child_pnAssertRukuDetails_id\n    WHERE pn_Code IS NOT NULL\n    AND serialNumber IS NOT NULL\n    AND DATE(pr.create_time) = CURDATE()\n    AND pr.warehouseEntryNumber &lt;&gt; 'WEd3791f0b'\n) AS temp1\nWHERE EXISTS (\n    SELECT *\n    FROM (\n        SELECT pn_Code, serialNumber\n        FROM pnassertbasic_ruku pr\n        LEFT JOIN pnassertruku pu ON pr.parent_pnAssertRuku_id = pu.child_pnAssertRukuDetails_id\n        WHERE pu.child_pnAssertRukuDetails_id IS NULL\n        AND pr.warehouseEntryNumber = 'WEd3791f0b'\n    ) AS temp2\n    WHERE temp1.pn_Code = temp2.pn_Code\n    AND temp1.serialNumber = temp2.serialNumber\n);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 EXISTS \u5173\u952e\u5b57\u5224\u65ad\u4e24\u4e2a\u8868\u4e2d\u662f\u5426\u5b58\u5728\u76f8\u540c\u8bb0\u5f55\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528 exists \u5173\u952e\u5b57\u68c0\u67e5\u4e24\u4e2a\u8868\u4e2d\u662f\u5426\u5b58\u5728\u5bf9\u5e94\u7684\u503c\uff1f \u8981\u627e\u51fa\u4e24\u4e2a\u8868\u4e2d\u662f\u5426\u5b58\u5728\u5bf9\u5e94\u7684\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528 exists \u5173\u952e\u5b57\u3002\u6b64\u5173\u952e\u5b57\u68c0\u67e5\u4e00\u4e2a\u5b50\u67e5\u8be2\u662f\u5426\u8fd4\u56de\u4efb\u4f55\u884c\uff0c\u5982\u679c\u8fd4\u56de\uff0c\u5219 exists \u8fd4\u56de true\uff1b\u5426\u5219\uff0c\u8fd4\u56de false\u3002 \u793a\u4f8b\u67e5\u8be2\uff1a \u4ee5\u4e0b\u67e5\u8be2\u4f7f\u7528 exists \u68c0\u67e5\u540d\u4e3a temp1 \u7684\u8868\u7684\u884c\u662f\u5426\u51fa\u73b0\u5728\u540d\u4e3a temp2 \u7684\u8868\u4e2d\uff1a select * from temp1 where exists ( select * from temp2 where temp1.pn_code = temp2.pn_code and temp1.serialnumber = temp2.serialnumber ); \u767b\u5f55\u540e\u590d\u5236 \u4fee\u6539\u540e\u7684\u67e5\u8be2\uff1a \u5728\u4f60\u7684\u60c5\u51b5\u4e0b\uff0c\u4f60\u9700\u8981\u68c0\u67e5\u4e3b\u8868\uff08temp1\uff09\u4e2d\u7684\u884c\u662f\u5426\u51fa\u73b0\u5728\u5b50\u8868\uff08temp2\uff09\u4e2d\u3002\u4fee\u6539\u540e\u7684\u67e5\u8be2\u5982\u4e0b\uff1a SELECT * FROM ( SELECT pn_Code, serialNumber FROM pnassertbasic_ruku pr LEFT JOIN pnassertruku pu [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-27718","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27718","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=27718"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27718\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27718"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27718"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27718"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}