{"id":5465,"date":"2023-06-27T21:51:04","date_gmt":"2023-06-27T13:51:04","guid":{"rendered":"https:\/\/ixyzero.com\/blog\/?p=5465"},"modified":"2023-06-27T21:51:04","modified_gmt":"2023-06-27T13:51:04","slug":"hive-sql%e4%b8%ad%e7%9a%84full-outer-join%e4%bd%bf%e7%94%a8%e5%ad%a6%e4%b9%a0","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/5465.html","title":{"rendered":"Hive SQL\u4e2d\u7684full outer join\u4f7f\u7528\u5b66\u4e60"},"content":{"rendered":"\n<p>=Start=<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u7f18\u7531\uff1a<\/h4>\n\n\n\n<p>\u7b80\u5355\u6574\u7406\u8bb0\u5f55\u4e00\u4e0bHive SQL\u4e2d\u7684 full outer join \u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u65b9\u4fbf\u540e\u9762\u6709\u9700\u8981\u7684\u65f6\u5019\u53c2\u8003\u3002\u5e73\u65f6\u6211\u7528\u7684\u6700\u591a\u7684\u662f\u8868\u5173\u8054\u662f left outer join \uff0c\u7528\u6765\u57fa\u4e8e\u8d77\u59cb\u88681\u4e2d\u7684\u7279\u5b9a\u5217\u53bb\u5176\u5b83\u7684\u8868\u4e2d\u5173\u8054\u3001\u6269\u5c55\u5b57\u6bb5\uff0c\u51fa\u53d1\u70b9\u5728\u4e8e\u8d77\u59cb\u88681\u4e2d\u7684\u884c\u6570\u636e\u5df2\u7ecf\u662f\u5168\u7684\u4e86\uff0c\u5269\u4e0b\u7684\u53ea\u9700\u8981\u57fa\u4e8e\u7279\u5b9a\u6761\u4ef6\u53bb\u6269\u5c55\u5217\uff0c\u8865\u5145\u66f4\u591a\u7684\u4fe1\u606f\u5373\u53ef\u3002<\/p>\n\n\n\n<p>\u4f46\u5176\u5b9e\u6709\u4e9b\u60c5\u51b5\u4e0b\uff0c\u8d77\u59cb\u88681\u4e0d\u4e00\u5b9a\u662f\u4e00\u5f20\u8868\uff0c\u800c\u662f\u9700\u8981\u4ece\u591a\u5f20\u8868\u4e2d\u8fdb\u884c union \u5408\u5e76\u624d\u80fd\u7ec4\u6210\u4e00\u4e2a\u8f83\u4e3a\u5b8c\u6574\u7684\u6570\u636e\uff0c\u8fd9\u65f6\u5c31\u53ef\u4ee5\u7528 full outer join \u6765\u5b9e\u73b0\u8fd9\u4e2a\u529f\u80fd\u3002\u56e0\u4e3a\u4e4b\u524d\u57fa\u672c\u6ca1\u7528\u8fc7\u8fd9\u4e2a\u5173\u8054\uff0c\u6240\u4ee5\u8fd9\u91cc\u6839\u636e\u7f51\u4e0a\u7684\u793a\u4f8b\u5b9e\u9645\u6267\u884c\u9a8c\u8bc1\uff0c\u597d\u6709\u4e00\u4e2a\u66f4\u6df1\u7684\u7406\u89e3\u548c\u8bb0\u5fc6\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u6b63\u6587\uff1a<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">\u53c2\u8003\u89e3\u7b54\uff1a<\/h5>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>\u5168\u5173\u8054\uff08full outer join\u3001full join\uff09\u7684\u539f\u7406\u662f\u5148\u5de6\u5173\u8054\u518d\u53f3\u5173\u8054\uff0c\u7136\u540e\u628a\u7ed3\u679c\u7528 union \u5408\u5e76\u53bb\u91cd\u518d\u8fd4\u56de<\/strong>\uff08union\u4f1a\u5bf9\u4e24\u4e2a\u5b50\u67e5\u8be2\u7684\u7ed3\u679c\u53bb\u91cd\u5408\u5e76\uff0c\u800cunion all\u4e0d\u4f1a\u5bf9\u5b50\u67e5\u8be2\u7ed3\u679c\u53bb\u91cd\u5904\u7406\uff09\uff0c<strong>\u5173\u8054\u4e0d\u5230\u7684\u5b57\u6bb5\u88ab\u81ea\u52a8\u7f6e\u4e3a NULL\u3002\u662f\u5426\u6307\u5b9a outer \u5173\u952e\u5b57\uff0c\u5bf9\u67e5\u8be2\u7ed3\u679c\u65e0\u5f71\u54cd<\/strong>\u3002<\/p>\n\n\n\n<p><strong>\u6ce8\u610f\uff1afull join\u65f6\u5019\uff0cHive\u4e0d\u4f1a\u4f7f\u7528MapJoin\u6765\u4f18\u5316\u3002<\/strong><\/p>\n<\/blockquote>\n\n\n\n<h5 class=\"wp-block-heading\">\u521b\u5efa2\u5f20\u8868\u7528\u4e8e\u6d4b\u8bd5<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code># test.user_info\nc_id,c_name,c_age\n1,'zhangsan',22\n2,'lisi',34\n3,'wangwu',21\n7,'zhaoliu',33\n8,'jiuba',44\n9,'liuqi',44\n\n# test.order_info\norder_id,c_id,order_date\n1,1,'2022-03-01'\n2,2,'2022-03-02'\n3,3,'2022-03-03'\n4,4,'2022-03-04'\n5,5,'2022-03-05'\n6,6,'2022-03-06'\n7,1,'2022-03-11'\n\n\u4ee5\u4e0a2\u4e2a\u8868\u4e4b\u95f4\u901a\u8fc7 c_id \u5b57\u6bb5\u8fdb\u884c\u5173\u8054\u3002<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">\u51e0\u79cd\u5173\u8054\u8bed\u6cd5\u7684\u6548\u679c\u5982\u4e0b<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>select\n*\nfrom\ntest.user_info -- 6 \u884c\n;\n\nselect\n*\nfrom\ntest.order_info -- 7 \u884c\n;\n\n\nselect\nt1.*,t2.*\nfrom\ntest.user_info t1\n-- left outer join -- 6+1 \u884c\n-- right outer join -- 7 \u884c\nfull outer join -- 10 \u884c\ntest.order_info t2\non t1.c_id = t2.c_id\n;\n\n\n\/*left outer join\nt1_c_id    t1_c_name   t1_c_age    t2_order_id t2_c_id t2_order_date   \n1    zhangsan    22  7   1   2022-03-11\n1    zhangsan    22  1   1   2022-03-01\n2    lisi    34  2   2   2022-03-02\n3    wangwu  21  3   3   2022-03-03\n7    zhaoliu 33          \n8    jiuba   44          \n9    liuqi   44          \n*\/\n\n\/*right outer join\nt1_c_id    t1_c_name   t1_c_age    t2_order_id t2_c_id t2_order_date   \n            4   4   2022-03-04\n            5   5   2022-03-05\n3    wangwu  21  3   3   2022-03-03\n1    zhangsan    22  7   1   2022-03-11\n1    zhangsan    22  1   1   2022-03-01\n            6   6   2022-03-06\n2    lisi    34  2   2   2022-03-02\n*\/\n\n\n\/* full outer join\nt1_c_id    t1_c_name   t1_c_age    t2_order_id t2_c_id t2_order_date   \n8    jiuba   44          \n9    liuqi   44          \n2    lisi    34  2   2   2022-03-02\n7    zhaoliu 33          \n1    zhangsan    22  7   1   2022-03-11\n1    zhangsan    22  1   1   2022-03-01\n3    wangwu  21  3   3   2022-03-03\n            5   5   2022-03-05\n            4   4   2022-03-04\n            6   6   2022-03-06\n*\/\n\n-- \u548c\u4e0a\u9762\u7684 full outer join \u6548\u679c\u7b49\u4ef7\nselect\nt1.*,t2.*\nfrom\ntest.user_info t1\nleft outer join -- 6+1 \u884c\ntest.order_info t2\non t1.c_id = t2.c_id\n\nunion\n\nselect\nt1.*,t2.*\nfrom\ntest.user_info t1\nright outer join -- 7 \u884c\ntest.order_info t2\non t1.c_id = t2.c_id\n;<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">\u53c2\u8003\u94fe\u63a5\uff1a<\/h5>\n\n\n\n<p>hive\u4e4bfull outer join\uff08\u5168\u8fde\u63a5\uff09\u4f7f\u7528\u65b9\u6cd5 #\u5f88\u8be6\u7ec6<br><a href=\"https:\/\/blog.csdn.net\/qq_36249352\/article\/details\/124017263\">https:\/\/blog.csdn.net\/qq_36249352\/article\/details\/124017263<\/a><\/p>\n\n\n\n<p>Hive Join \u7684\u539f\u7406\u4e0e\u673a\u5236<br><a href=\"https:\/\/www.hadoopdoc.com\/hive\/hive-join\">https:\/\/www.hadoopdoc.com\/hive\/hive-join<\/a><\/p>\n\n\n\n<p>[\u4e00\u8d77\u5b66Hive]\u4e4b\u5341\u4e00-Hive\u4e2dJoin\u7684\u7c7b\u578b\u548c\u7528\u6cd5<br><a href=\"http:\/\/lxw1234.com\/archives\/2015\/06\/315.htm\">http:\/\/lxw1234.com\/archives\/2015\/06\/315.htm<\/a><\/p>\n\n\n\n<p>=END=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=Start= \u7f18\u7531\uff1a \u7b80\u5355\u6574\u7406\u8bb0\u5f55\u4e00\u4e0bHive SQL\u4e2d\u7684 full outer join \u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u65b9\u4fbf [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,23,7],"tags":[1967,1261,421,1262,1968,1307],"class_list":["post-5465","post","type-post","status-publish","format-standard","hentry","category-database","category-knowledgebase-2","category-programing","tag-full-join","tag-hive","tag-join","tag-sql","tag-union","tag-union-all"],"views":2640,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/5465","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=5465"}],"version-history":[{"count":1,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/5465\/revisions"}],"predecessor-version":[{"id":5466,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/5465\/revisions\/5466"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=5465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=5465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=5465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}