{"id":152243,"date":"2024-11-01T21:18:20","date_gmt":"2024-11-01T13:18:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/152243\/"},"modified":"2024-11-01T21:18:21","modified_gmt":"2024-11-01T13:18:21","slug":"%e4%b8%8d%e5%90%8c%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e8%a1%a8%e5%a6%82%e4%bd%95%e5%b0%8d%e6%af%94%ef%bc%9f-%e6%80%8e%e6%a8%a3%e5%b0%8d%e6%af%94%e5%85%a9%e5%bc%b5%e8%a1%a8%e7%9a%84%e4%b8%8d%e5%90%8c","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/152243\/","title":{"rendered":"\u4e0d\u540c\u6578\u64da\u5eab\u7684\u8868\u5982\u4f55\u5c0d\u6bd4\uff1f (\u600e\u6a23\u5c0d\u6bd4\u5169\u5f35\u8868\u7684\u4e0d\u540c\u7684\u6578\u64da\u5eab)"},"content":{"rendered":"<h1 id=\"%e4%b8%8d%e5%90%8c%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e8%a1%a8%e5%a6%82%e4%bd%95%e5%b0%8d%e6%af%94%ef%bc%9f-rVwYBEcgPh\">\u4e0d\u540c\u6578\u64da\u5eab\u7684\u8868\u5982\u4f55\u5c0d\u6bd4\uff1f<\/h1>\n<p>\u5728\u6578\u64da\u7ba1\u7406\u548c\u5206\u6790\u7684\u904e\u7a0b\u4e2d\uff0c\u5c0d\u6bd4\u4e0d\u540c\u6578\u64da\u5eab\u4e2d\u7684\u8868\u683c\u662f\u5e38\u898b\u7684\u9700\u6c42\u3002\u7121\u8ad6\u662f\u70ba\u4e86\u6578\u64da\u9077\u79fb\u3001\u6578\u64da\u6574\u5408\uff0c\u9084\u662f\u70ba\u4e86\u78ba\u4fdd\u6578\u64da\u7684\u4e00\u81f4\u6027\uff0c\u4e86\u89e3\u5982\u4f55\u6709\u6548\u5730\u5c0d\u6bd4\u5169\u5f35\u8868\u7684\u6578\u64da\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5e7e\u7a2e\u5e38\u898b\u7684\u6578\u64da\u5eab\u7cfb\u7d71\uff0c\u4e26\u63d0\u4f9b\u5c0d\u6bd4\u8868\u683c\u7684\u5177\u9ad4\u65b9\u6cd5\u548c\u793a\u4f8b\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%9c%80%e8%a6%81%e5%b0%8d%e6%af%94%e6%95%b8%e6%93%9a%e5%ba%ab%e8%a1%a8%ef%bc%9f-rVwYBEcgPh\">\u70ba\u4ec0\u9ebc\u9700\u8981\u5c0d\u6bd4\u6578\u64da\u5eab\u8868\uff1f<\/h2>\n<p>\u5c0d\u6bd4\u6578\u64da\u5eab\u8868\u7684\u539f\u56e0\u6709\u5f88\u591a\uff0c\u4e3b\u8981\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u64da\u4e00\u81f4\u6027\uff1a<\/strong>\u78ba\u4fdd\u4e0d\u540c\u6578\u64da\u5eab\u4e2d\u7684\u6578\u64da\u4fdd\u6301\u4e00\u81f4\uff0c\u7279\u5225\u662f\u5728\u6578\u64da\u540c\u6b65\u7684\u60c5\u6cc1\u4e0b\u3002<\/li>\n<li><strong>\u6578\u64da\u9077\u79fb\uff1a<\/strong>\u5728\u5c07\u6578\u64da\u5f9e\u4e00\u500b\u6578\u64da\u5eab\u9077\u79fb\u5230\u53e6\u4e00\u500b\u6578\u64da\u5eab\u6642\uff0c\u5c0d\u6bd4\u53ef\u4ee5\u5e6b\u52a9\u78ba\u8a8d\u9077\u79fb\u7684\u5b8c\u6574\u6027\u3002<\/li>\n<li><strong>\u6578\u64da\u6e05\u7406\uff1a<\/strong>\u8b58\u5225\u91cd\u8907\u6216\u4e0d\u6b63\u78ba\u7684\u6578\u64da\uff0c\u5f9e\u800c\u63d0\u9ad8\u6578\u64da\u8cea\u91cf\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%b8%b8%e8%a6%8b%e7%9a%84%e6%95%b8%e6%93%9a%e5%ba%ab%e7%b3%bb%e7%b5%b1-rVwYBEcgPh\">\u5e38\u898b\u7684\u6578\u64da\u5eab\u7cfb\u7d71<\/h2>\n<p>\u5728\u9032\u884c\u6578\u64da\u5c0d\u6bd4\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u4e86\u89e3\u4e00\u4e9b\u5e38\u898b\u7684\u6578\u64da\u5eab\u7cfb\u7d71\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>MySQL\uff1a<\/strong>\u4e00\u7a2e\u958b\u6e90\u7684\u95dc\u806f\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bcWeb\u61c9\u7528\u3002<\/li>\n<li><strong>PostgreSQL\uff1a<\/strong>\u4e00\u7a2e\u529f\u80fd\u5f37\u5927\u7684\u958b\u6e90\u95dc\u806f\u6578\u64da\u5eab\uff0c\u652f\u6301\u8907\u96dc\u67e5\u8a62\u548c\u6578\u64da\u5b8c\u6574\u6027\u3002<\/li>\n<li><strong>SQL Server\uff1a<\/strong>\u5fae\u8edf\u7684\u95dc\u806f\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u9069\u5408\u4f01\u696d\u7d1a\u61c9\u7528\u3002<\/li>\n<li><strong>Oracle\uff1a<\/strong>\u4e00\u7a2e\u5546\u696d\u6578\u64da\u5eab\uff0c\u63d0\u4f9b\u9ad8\u6027\u80fd\u548c\u9ad8\u53ef\u7528\u6027\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%b0%8d%e6%af%94%e5%85%a9%e5%bc%b5%e8%a1%a8%e7%9a%84%e6%95%b8%e6%93%9a-rVwYBEcgPh\">\u5982\u4f55\u5c0d\u6bd4\u5169\u5f35\u8868\u7684\u6578\u64da<\/h2>\n<p>\u5c0d\u6bd4\u5169\u5f35\u8868\u7684\u6578\u64da\u53ef\u4ee5\u901a\u904e\u591a\u7a2e\u65b9\u6cd5\u9032\u884c\uff0c\u4ee5\u4e0b\u662f\u5e7e\u7a2e\u5e38\u898b\u7684\u65b9\u6cd5\uff1a<\/p>\n<h3 id=\"1-%e4%bd%bf%e7%94%a8sql%e6%9f%a5%e8%a9%a2-rVwYBEcgPh\">1. \u4f7f\u7528SQL\u67e5\u8a62<\/h3>\n<p>\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u662f\u4f7f\u7528SQL\u67e5\u8a62\u4f86\u5c0d\u6bd4\u5169\u5f35\u8868\u7684\u6578\u64da\u3002\u4ee5\u4e0b\u662fMySQL\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>SELECT * FROM table1\nWHERE NOT EXISTS (\n    SELECT * FROM table2\n    WHERE table1.id = table2.id\n);<\/code><\/pre>\n<p>\u9019\u6bb5\u67e5\u8a62\u5c07\u8fd4\u56de\u5728table1\u4e2d\u5b58\u5728\u4f46\u5728table2\u4e2d\u4e0d\u5b58\u5728\u7684\u6240\u6709\u8a18\u9304\u3002<\/p>\n<h3 id=\"2-%e4%bd%bf%e7%94%a8%e6%95%b8%e6%93%9a%e5%ba%ab%e5%b7%a5%e5%85%b7-rVwYBEcgPh\">2. \u4f7f\u7528\u6578\u64da\u5eab\u5de5\u5177<\/h3>\n<p>\u8a31\u591a\u6578\u64da\u5eab\u7ba1\u7406\u5de5\u5177\uff08\u5982DBeaver\u3001HeidiSQL\u7b49\uff09\u63d0\u4f9b\u4e86\u53ef\u8996\u5316\u7684\u6578\u64da\u5c0d\u6bd4\u529f\u80fd\u3002\u9019\u4e9b\u5de5\u5177\u901a\u5e38\u5141\u8a31\u7528\u6236\u9078\u64c7\u5169\u5f35\u8868\uff0c\u7136\u5f8c\u81ea\u52d5\u751f\u6210\u5c0d\u6bd4\u5831\u544a\uff0c\u986f\u793a\u5dee\u7570\u3002<\/p>\n<h3 id=\"3-%e4%bd%bf%e7%94%a8%e7%b7%a8%e7%a8%8b%e8%aa%9e%e8%a8%80-rVwYBEcgPh\">3. \u4f7f\u7528\u7de8\u7a0b\u8a9e\u8a00<\/h3>\n<p>\u5982\u679c\u9700\u8981\u9032\u884c\u66f4\u8907\u96dc\u7684\u5c0d\u6bd4\uff0c\u53ef\u4ee5\u4f7f\u7528\u7de8\u7a0b\u8a9e\u8a00\uff08\u5982Python\uff09\u4f86\u5be6\u73fe\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528Python\u548cpandas\u5eab\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>import pandas as pd\n\n# \u8b80\u53d6\u6578\u64da\ntable1 = pd.read_sql('SELECT * FROM table1', connection)\ntable2 = pd.read_sql('SELECT * FROM table2', connection)\n\n# \u5c0d\u6bd4\u6578\u64da\ndiff = pd.concat([table1, table2]).drop_duplicates(keep=False)\nprint(diff)<\/code><\/pre>\n<p>\u9019\u6bb5\u4ee3\u78bc\u5c07\u986f\u793a\u5728\u5169\u5f35\u8868\u4e2d\u5b58\u5728\u5dee\u7570\u7684\u6240\u6709\u8a18\u9304\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-rVwYBEcgPh\">\u7d50\u8ad6<\/h2>\n<p>\u5c0d\u6bd4\u4e0d\u540c\u6578\u64da\u5eab\u4e2d\u7684\u8868\u683c\u662f\u4e00\u9805\u91cd\u8981\u7684\u4efb\u52d9\uff0c\u7121\u8ad6\u662f\u70ba\u4e86\u6578\u64da\u4e00\u81f4\u6027\u3001\u6578\u64da\u9077\u79fb\u9084\u662f\u6578\u64da\u6e05\u7406\u3002\u901a\u904e\u4f7f\u7528SQL\u67e5\u8a62\u3001\u6578\u64da\u5eab\u5de5\u5177\u6216\u7de8\u7a0b\u8a9e\u8a00\uff0c\u60a8\u53ef\u4ee5\u6709\u6548\u5730\u8b58\u5225\u548c\u8655\u7406\u6578\u64da\u5dee\u7570\u3002\u96a8\u8457\u6578\u64da\u91cf\u7684\u589e\u52a0\uff0c\u638c\u63e1\u9019\u4e9b\u6280\u80fd\u5c07\u5c0d\u6578\u64da\u7ba1\u7406\u5de5\u4f5c\u5927\u6709\u88e8\u76ca\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u53ef\u9760\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u652f\u6301\u60a8\u7684\u6578\u64da\u5eab\u9700\u6c42\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u5e6b\u52a9\u60a8\u8f15\u9b06\u7ba1\u7406\u548c\u5c0d\u6bd4\u6578\u64da\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5c0d\u6bd4\u4e0d\u540c\u6578\u64da\u5eab\u4e2d\u7684\u8868\uff0c\u638c\u63e1\u6709\u6548\u7684\u65b9\u6cd5\u548c\u5de5\u5177\uff0c\u8f15\u9b06\u8b58\u5225\u6578\u64da\u5dee\u7570\u8207\u4e00\u81f4\u6027\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-152243","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/152243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=152243"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/152243\/revisions"}],"predecessor-version":[{"id":152244,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/152243\/revisions\/152244"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=152243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=152243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=152243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}