{"id":189382,"date":"2024-11-12T07:17:20","date_gmt":"2024-11-11T23:17:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/189382\/"},"modified":"2024-11-12T07:17:21","modified_gmt":"2024-11-11T23:17:21","slug":"%e7%b5%b1%e8%a8%88%e7%9b%b8%e5%90%8c%e6%95%b8%e6%93%9a%ef%bc%9a%e5%a6%82%e4%bd%95%e6%af%94%e8%bc%83%e5%85%a9%e5%80%8b%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%9f-%e5%a6%82%e4%bd%95%e7%b5%b1%e8%a8%88%e5%85%a9","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/189382\/","title":{"rendered":"\u7d71\u8a08\u76f8\u540c\u6578\u64da\uff1a\u5982\u4f55\u6bd4\u8f03\u5169\u500b\u6578\u64da\u5eab\uff1f (\u5982\u4f55\u7d71\u8a08\u5169\u7d44\u6578\u64da\u7684\u76f8\u540c\u6578\u64da\u5eab)"},"content":{"rendered":"<h1 id=\"%e7%b5%b1%e8%a8%88%e7%9b%b8%e5%90%8c%e6%95%b8%e6%93%9a%ef%bc%9a%e5%a6%82%e4%bd%95%e6%af%94%e8%bc%83%e5%85%a9%e5%80%8b%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%9f-NROlUWkeoq\">\u7d71\u8a08\u76f8\u540c\u6578\u64da\uff1a\u5982\u4f55\u6bd4\u8f03\u5169\u500b\u6578\u64da\u5eab\uff1f<\/h1>\n<p>\u5728\u6578\u64da\u5206\u6790\u7684\u904e\u7a0b\u4e2d\uff0c\u7d93\u5e38\u9700\u8981\u6bd4\u8f03\u5169\u500b\u6578\u64da\u5eab\uff0c\u4ee5\u627e\u51fa\u5b83\u5011\u4e4b\u9593\u7684\u76f8\u540c\u6578\u64da\u3002\u9019\u7a2e\u6bd4\u8f03\u4e0d\u50c5\u80fd\u5e6b\u52a9\u4f01\u696d\u4e86\u89e3\u6578\u64da\u7684\u4e00\u81f4\u6027\uff0c\u9084\u80fd\u63ed\u793a\u6f5b\u5728\u7684\u6578\u64da\u554f\u984c\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u6709\u6548\u5730\u7d71\u8a08\u548c\u6bd4\u8f03\u5169\u7d44\u6578\u64da\u5eab\u4e2d\u7684\u76f8\u540c\u6578\u64da\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5be6\u7528\u7684\u793a\u4f8b\u548c\u4ee3\u78bc\u7247\u6bb5\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%9c%80%e8%a6%81%e6%af%94%e8%bc%83%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%9f-NROlUWkeoq\">\u70ba\u4ec0\u9ebc\u9700\u8981\u6bd4\u8f03\u6578\u64da\u5eab\uff1f<\/h2>\n<p>\u6578\u64da\u5eab\u6bd4\u8f03\u7684\u4e3b\u8981\u76ee\u7684\u662f\u78ba\u4fdd\u6578\u64da\u7684\u6e96\u78ba\u6027\u548c\u4e00\u81f4\u6027\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u61c9\u7528\u5834\u666f\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u64da\u9077\u79fb\uff1a<\/strong>\u5728\u5c07\u6578\u64da\u5f9e\u4e00\u500b\u7cfb\u7d71\u9077\u79fb\u5230\u53e6\u4e00\u500b\u7cfb\u7d71\u6642\uff0c\u78ba\u4fdd\u6578\u64da\u7684\u5b8c\u6574\u6027\u81f3\u95dc\u91cd\u8981\u3002<\/li>\n<li><strong>\u6578\u64da\u6574\u5408\uff1a<\/strong>\u7576\u4f01\u696d\u5408\u4f75\u6216\u6536\u8cfc\u6642\uff0c\u6574\u5408\u4e0d\u540c\u4f86\u6e90\u7684\u6578\u64da\u5eab\u662f\u5fc5\u8981\u7684\u3002<\/li>\n<li><strong>\u6578\u64da\u6e05\u7406\uff1a<\/strong>\u5b9a\u671f\u6bd4\u8f03\u6578\u64da\u5eab\u53ef\u4ee5\u5e6b\u52a9\u8b58\u5225\u91cd\u8907\u6216\u4e0d\u4e00\u81f4\u7684\u6578\u64da\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%af%94%e8%bc%83%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%ad%a5%e9%a9%9f-NROlUWkeoq\">\u6bd4\u8f03\u6578\u64da\u5eab\u7684\u57fa\u672c\u6b65\u9a5f<\/h2>\n<p>\u6bd4\u8f03\u5169\u500b\u6578\u64da\u5eab\u7684\u904e\u7a0b\u53ef\u4ee5\u5206\u70ba\u5e7e\u500b\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"1-%e7%a2%ba%e5%ae%9a%e6%af%94%e8%bc%83%e7%9a%84%e7%af%84%e5%9c%8d-NROlUWkeoq\">1. \u78ba\u5b9a\u6bd4\u8f03\u7684\u7bc4\u570d<\/h3>\n<p>\u9996\u5148\uff0c\u9700\u8981\u660e\u78ba\u8981\u6bd4\u8f03\u7684\u6578\u64da\u7bc4\u570d\u3002\u9019\u53ef\u80fd\u5305\u62ec\u7279\u5b9a\u7684\u8868\u683c\u3001\u5b57\u6bb5\u6216\u6574\u500b\u6578\u64da\u5eab\u3002\u78ba\u5b9a\u7bc4\u570d\u5f8c\uff0c\u53ef\u4ee5\u66f4\u6709\u6548\u5730\u9032\u884c\u6bd4\u8f03\u3002<\/p>\n<h3 id=\"2-%e6%8f%90%e5%8f%96%e6%95%b8%e6%93%9a-NROlUWkeoq\">2. \u63d0\u53d6\u6578\u64da<\/h3>\n<p>\u5f9e\u5169\u500b\u6578\u64da\u5eab\u4e2d\u63d0\u53d6\u9700\u8981\u6bd4\u8f03\u7684\u6578\u64da\u3002\u9019\u901a\u5e38\u53ef\u4ee5\u901a\u904e SQL \u67e5\u8a62\u4f86\u5be6\u73fe\u3002\u4f8b\u5982\uff0c\u5047\u8a2d\u6211\u5011\u6709\u5169\u500b\u6578\u64da\u5eab\uff0c\u5206\u5225\u70ba <code>db1<\/code> \u548c <code>db2<\/code>\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b SQL \u67e5\u8a62\u4f86\u63d0\u53d6\u6578\u64da\uff1a<\/p>\n<pre><code>SELECT * FROM db1.table_name;\nSELECT * FROM db2.table_name;<\/code><\/pre>\n<h3 id=\"3-%e6%95%b8%e6%93%9a%e6%b8%85%e7%90%86-NROlUWkeoq\">3. \u6578\u64da\u6e05\u7406<\/h3>\n<p>\u5728\u6bd4\u8f03\u4e4b\u524d\uff0c\u5c0d\u63d0\u53d6\u7684\u6578\u64da\u9032\u884c\u6e05\u7406\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u9019\u5305\u62ec\u53bb\u9664\u91cd\u8907\u6578\u64da\u3001\u586b\u88dc\u7f3a\u5931\u503c\u4ee5\u53ca\u6a19\u6e96\u5316\u6578\u64da\u683c\u5f0f\u3002\u4f8b\u5982\uff0c\u5982\u679c\u67d0\u4e9b\u5b57\u6bb5\u7684\u683c\u5f0f\u4e0d\u4e00\u81f4\uff0c\u5247\u9700\u8981\u9032\u884c\u8f49\u63db\u3002<\/p>\n<h3 id=\"4-%e6%af%94%e8%bc%83%e6%95%b8%e6%93%9a-NROlUWkeoq\">4. \u6bd4\u8f03\u6578\u64da<\/h3>\n<p>\u6bd4\u8f03\u6578\u64da\u53ef\u4ee5\u4f7f\u7528\u591a\u7a2e\u65b9\u6cd5\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u6280\u8853\uff1a<\/p>\n<ul>\n<li><strong>\u4f7f\u7528 SQL JOIN\uff1a<\/strong>\u53ef\u4ee5\u4f7f\u7528 SQL \u7684 JOIN \u8a9e\u53e5\u4f86\u6bd4\u8f03\u5169\u500b\u6578\u64da\u5eab\u4e2d\u7684\u6578\u64da\u3002\u4f8b\u5982\uff1a<\/li>\n<\/ul>\n<pre><code>SELECT a.*\nFROM db1.table_name a\nJOIN db2.table_name b ON a.id = b.id;<\/code><\/pre>\n<ul>\n<li><strong>\u4f7f\u7528 Python\uff1a<\/strong>\u5982\u679c\u6578\u64da\u91cf\u8f03\u5927\uff0c\u53ef\u4ee5\u8003\u616e\u4f7f\u7528 Python \u7684 pandas \u5eab\u4f86\u9032\u884c\u6bd4\u8f03\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff1a<\/li>\n<\/ul>\n<pre><code>import pandas as pd\n\n# \u8b80\u53d6\u6578\u64da\ndb1_data = pd.read_csv('db1.csv')\ndb2_data = pd.read_csv('db2.csv')\n\n# \u6bd4\u8f03\u6578\u64da\ncommon_data = pd.merge(db1_data, db2_data, on='id')\nprint(common_data)<\/code><\/pre>\n<h3 id=\"5-%e5%88%86%e6%9e%90%e7%b5%90%e6%9e%9c-NROlUWkeoq\">5. \u5206\u6790\u7d50\u679c<\/h3>\n<p>\u6700\u5f8c\uff0c\u5c0d\u6bd4\u8f03\u7684\u7d50\u679c\u9032\u884c\u5206\u6790\uff0c\u627e\u51fa\u76f8\u540c\u6578\u64da\u548c\u5dee\u7570\u6578\u64da\u3002\u9019\u53ef\u4ee5\u5e6b\u52a9\u4f01\u696d\u505a\u51fa\u66f4\u660e\u667a\u7684\u6c7a\u7b56\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-NROlUWkeoq\">\u7d50\u8ad6<\/h2>\n<p>\u6bd4\u8f03\u5169\u500b\u6578\u64da\u5eab\u4e2d\u7684\u76f8\u540c\u6578\u64da\u662f\u4e00\u500b\u91cd\u8981\u7684\u904e\u7a0b\uff0c\u80fd\u5920\u5e6b\u52a9\u4f01\u696d\u78ba\u4fdd\u6578\u64da\u7684\u6e96\u78ba\u6027\u548c\u4e00\u81f4\u6027\u3002\u901a\u904e\u660e\u78ba\u6bd4\u8f03\u7bc4\u570d\u3001\u63d0\u53d6\u548c\u6e05\u7406\u6578\u64da\u3001\u4f7f\u7528\u5408\u9069\u7684\u6bd4\u8f03\u6280\u8853\uff0c\u4f01\u696d\u53ef\u4ee5\u6709\u6548\u5730\u9032\u884c\u6578\u64da\u5206\u6790\u3002\u96a8\u8457\u6578\u64da\u91cf\u7684\u589e\u52a0\uff0c\u9019\u4e00\u904e\u7a0b\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u91cd\u8981\uff0c\u9078\u64c7\u5408\u9069\u7684\u5de5\u5177\u548c\u6280\u8853\u5c07\u662f\u6210\u529f\u7684\u95dc\u9375\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\u6bd4\u8f03\u548c\u5206\u6790\u9700\u6c42\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u6bd4\u8f03\u5169\u500b\u6578\u64da\u5eab\u4e2d\u7684\u76f8\u540c\u6578\u64da\uff0c\u638c\u63e1\u7d71\u8a08\u6280\u5de7\uff0c\u63d0\u5347\u6578\u64da\u5206\u6790\u80fd\u529b\uff0c\u52a9\u4f60\u505a\u51fa\u660e\u667a\u6c7a\u7b56\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-189382","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/189382","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=189382"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/189382\/revisions"}],"predecessor-version":[{"id":189383,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/189382\/revisions\/189383"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=189382"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=189382"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=189382"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}