{"id":2620,"date":"2020-12-29T13:48:29","date_gmt":"2020-12-29T05:48:29","guid":{"rendered":"https:\/\/www.gbase8.cn\/?p=2620"},"modified":"2021-06-30T09:28:31","modified_gmt":"2021-06-30T01:28:31","slug":"gbase-8a-olap%e5%87%bd%e6%95%b0group-by-grouping-sets%e7%9a%84%e4%bd%bf%e7%94%a8%e6%a0%b7%e4%be%8b","status":"publish","type":"post","link":"https:\/\/www.gbase8.cn\/en\/2620","title":{"rendered":"\u5357\u5927\u901a\u7528GBase 8a OLAP\u51fd\u6570group by grouping sets\u7684\u4f7f\u7528\u6837\u4f8b"},"content":{"rendered":"<p>GBase 8a\u7684group grouping sets\u529f\u80fd,\u5bf9\u540e\u9762\u62ec\u53f7\u91cc\u7684 n \u4e2a\u5b57\u6bb5\u6216\u8868\u8fbe\u5f0f\u5206\u522b\u505a GROUP BY \u64cd\u4f5c\uff0c\u6700\u540e\u5c06\u7ed3\u679c\u5408\u5e76\u5728\u4e00\u8d77\u3002\u7b49\u540c\u4e8e\u591a\u4e2a\u5355\u72ec\u7684group by\u540e\u518d\u505a\u4e00\u4e2aunion all\u64cd\u4f5c\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-6a2aaddcbc77c\" 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-6a2aaddcbc77c\"  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\/2620\/#%E5%8F%82%E8%80%83\" >\u53c2\u8003<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.gbase8.cn\/en\/2620\/#%E8%AF%AD%E6%B3%95\" >\u8bed\u6cd5<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.gbase8.cn\/en\/2620\/#%E8%AF%B4%E6%98%8E\" >\u8bf4\u660e<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.gbase8.cn\/en\/2620\/#%E6%A0%B7%E4%BE%8B\" >\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-5\" href=\"https:\/\/www.gbase8.cn\/en\/2620\/#%E6%95%B0%E6%8D%AE%E6%A0%B7%E4%BE%8B\" >\u6570\u636e\u6837\u4f8b<\/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\/2620\/#%E8%8E%B7%E5%BE%97%E5%AD%A6%E7%94%9F%E5%92%8C%E5%AD%A6%E7%A7%91%E5%90%84%E8%87%AA%E7%9A%84%E6%B1%87%E6%80%BB%E7%BB%93%E6%9E%9C\" >\u83b7\u5f97\u5b66\u751f\u548c\u5b66\u79d1\u5404\u81ea\u7684\u6c47\u603b\u7ed3\u679c<\/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\/2620\/#%E5%8F%82%E8%80%83-2\" >\u53c2\u8003<\/a><\/li><\/ul><\/nav><\/div>\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\/6639\/\">GBase 8a\u7a97\u53e3\u51fd\u6570\u4f7f\u7528\u6837\u4f8b\u7d22\u5f15<\/a><br><a href=\"https:\/\/www.gbase8.cn\/en\/6761\/\">GBase 8a\u7684grouping\u51fd\u6570\u4f7f\u7528\u8bf4\u660e\u548c\u7528\u4f8b<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E8%AF%AD%E6%B3%95\"><\/span>\u8bed\u6cd5<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>GROUP BY GROUPING SETS( (\u2026),(\u2026),\u2026)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E8%AF%B4%E6%98%8E\"><\/span>\u8bf4\u660e<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>GROUP BY GROUPING SETS (A,B,C) (A\u3001B\u3001C \u4ee3\u8868\u8bed\u6cd5\u4e2d\u7684\u201c(\u2026)\u201d)<br>\u9996\u5148\u5bf9(A)\u8fdb\u884c GROUP BY\uff0c\u7136\u540e\u5bf9(B)\u8fdb\u884c GROUP BY\uff0c\u7136\u540e\u5bf9(C)\u8fdb\u884c GROUP BY\uff0c\u6700\u540e\u5c06\u6240\u6709\u7ed3\u679c\u5408\u5e76\u5728\u4e00\u8d77(\u76f8\u5f53\u4e8e UNION ALL \u64cd\u4f5c)\uff0c\u5982\u679c n \u4e2a\u5b57\u6bb5\u6216\u8868\u8fbe\u5f0f\u4e2d\u7684\u4e00\u4e2a\u6216\u591a\u4e2a\u5728\u67d0\u4e00\u5206\u7ec4\u4e2d\u4e0d\u51fa\u73b0\u5728 GROUP BY \u540e\u9762\uff0c\u7528 NULL \u4ee3\u66ff\u4e0d\u51fa\u73b0\u7684\u5b57\u6bb5\u6216\u8868\u8fbe\u5f0f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%A0%B7%E4%BE%8B\"><\/span>\u6837\u4f8b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%95%B0%E6%8D%AE%E6%A0%B7%E4%BE%8B\"><\/span>\u6570\u636e\u6837\u4f8b<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u7b80\u5355\u7684\u5b66\u751f\u79d1\u76ee\u8003\u8bd5\u8bb0\u5f55\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase&gt; select * from score;\n+--------+---------+-------+\n| name   | subject | score |\n+--------+---------+-------+\n| \u738b\u6d77   | \u8bed\u6587    |    86 |\n| \u738b\u6d77   | \u6570\u5b66    |    83 |\n| \u738b\u6d77   | \u82f1\u8bed    |    93 |\n| \u9676\u4fca   | \u8bed\u6587    |    88 |\n| \u9676\u4fca   | \u6570\u5b66    |    84 |\n| \u9676\u4fca   | \u82f1\u8bed    |    94 |\n| \u5218\u53ef   | \u8bed\u6587    |    80 |\n| \u5218\u53ef   | \u6570\u5b66    |    86 |\n| \u5218\u53ef   | \u82f1\u8bed    |    88 |\n| \u674e\u6625   | \u8bed\u6587    |    89 |\n| \u674e\u6625   | \u6570\u5b66    |    80 |\n| \u674e\u6625   | \u82f1\u8bed    |    87 |\n+--------+---------+-------+\n12 rows in set (Elapsed: 00:00:00.01)\n\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E8%8E%B7%E5%BE%97%E5%AD%A6%E7%94%9F%E5%92%8C%E5%AD%A6%E7%A7%91%E5%90%84%E8%87%AA%E7%9A%84%E6%B1%87%E6%80%BB%E7%BB%93%E6%9E%9C\"><\/span>\u83b7\u5f97\u5b66\u751f\u548c\u5b66\u79d1\u5404\u81ea\u7684\u6c47\u603b\u7ed3\u679c<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase&gt; select name,subject,sum(score) from score group by grouping sets(name,subject);\n+--------+---------+------------+\n| name   | subject | sum(score) |\n+--------+---------+------------+\n| NULL   | \u8bed\u6587    |        343 |\n| NULL   | \u6570\u5b66    |        333 |\n| NULL   | \u82f1\u8bed    |        362 |\n| \u738b\u6d77   | NULL    |        262 |\n| \u9676\u4fca   | NULL    |        266 |\n| \u5218\u53ef   | NULL    |        254 |\n| \u674e\u6625   | NULL    |        256 |\n+--------+---------+------------+\n7 rows in set (Elapsed: 00:00:00.02)\n<\/code><\/pre>\n\n\n\n<p>\u591a\u4e2aSets\u4e4b\u95f4\u4e5f\u662funion all\u5173\u7cfb\u3002\u672c\u4f8b\u5c31\u7b80\u5355\u7684\u5c06\u4e0a\u4e00\u4e2a\u7528\u4f8b\u76842\u4e2a\u6761\u4ef6\uff0c\u62c6\u5206\u4e00\u4e0b\u3002\u7ed3\u679c\u662f\u4e00\u6837\u7684\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase&gt; select name,subject,sum(score) from score group by grouping sets((name),(subject));\n+--------+---------+------------+\n| name   | subject | sum(score) |\n+--------+---------+------------+\n| NULL   | \u8bed\u6587    |        343 |\n| NULL   | \u6570\u5b66    |        333 |\n| NULL   | \u82f1\u8bed    |        362 |\n| \u738b\u6d77   | NULL    |        262 |\n| \u9676\u4fca   | NULL    |        266 |\n| \u5218\u53ef   | NULL    |        254 |\n| \u674e\u6625   | NULL    |        256 |\n+--------+---------+------------+\n7 rows in set (Elapsed: 00:00:00.02)\n\ngbase&gt; select name,subject,sum(score) from score group by grouping sets(name,(name,subject));\n+--------+---------+------------+\n| name   | subject | sum(score) |\n+--------+---------+------------+\n| \u738b\u6d77   | \u8bed\u6587    |         86 |\n| \u738b\u6d77   | \u6570\u5b66    |         83 |\n| \u738b\u6d77   | \u82f1\u8bed    |         93 |\n| \u9676\u4fca   | \u8bed\u6587    |         88 |\n| \u9676\u4fca   | \u6570\u5b66    |         84 |\n| \u9676\u4fca   | \u82f1\u8bed    |         94 |\n| \u5218\u53ef   | \u8bed\u6587    |         80 |\n| \u5218\u53ef   | \u6570\u5b66    |         86 |\n| \u5218\u53ef   | \u82f1\u8bed    |         88 |\n| \u674e\u6625   | \u8bed\u6587    |         89 |\n| \u674e\u6625   | \u6570\u5b66    |         80 |\n| \u674e\u6625   | \u82f1\u8bed    |         87 |\n| \u738b\u6d77   | NULL    |        262 |\n| \u9676\u4fca   | NULL    |        266 |\n| \u5218\u53ef   | NULL    |        254 |\n| \u674e\u6625   | NULL    |        256 |\n+--------+---------+------------+\n16 rows in set (Elapsed: 00:00:00.04)\n\n<\/code><\/pre>\n\n\n\n<p>\u5982\u4e0a\u7b2c\u4e8c\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u7b2c\u4e00\u90e8\u5206\u662fname, \u7b2c\u4e8c\u90e8\u5206\u662f(name,subject)\u4e24\u4e2a\u5b57\u6bb5\u4e00\u8d77\u3002<\/p>\n\n\n\n<p>\u6ce8\u610f\uff0c\u4e0d\u8003\u8651\u91cd\u590d\uff0c\u4e5f\u5c31\u662f\u4f60\u53ef\u4ee5\u5199\u591a\u4e2aname\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase&gt; select name,subject,sum(score) from score group by grouping sets(name,name,subject);\n+--------+---------+------------+\n| name   | subject | sum(score) |\n+--------+---------+------------+\n| NULL   | \u8bed\u6587    |        343 |\n| NULL   | \u6570\u5b66    |        333 |\n| NULL   | \u82f1\u8bed    |        362 |\n| \u738b\u6d77   | NULL    |        262 |\n| \u9676\u4fca   | NULL    |        266 |\n| \u5218\u53ef   | NULL    |        254 |\n| \u674e\u6625   | NULL    |        256 |\n| \u738b\u6d77   | NULL    |        262 |\n| \u9676\u4fca   | NULL    |        266 |\n| \u5218\u53ef   | NULL    |        254 |\n| \u674e\u6625   | NULL    |        256 |\n+--------+---------+------------+\n11 rows in set (Elapsed: 00:00:00.03)\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%8F%82%E8%80%83-2\"><\/span>\u53c2\u8003<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><a href=\"https:\/\/www.gbase8.cn\/en\/tag\/olap\/\">\u5176\u5b83OLAP\u51fd\u6570\u8bf7\u53c2\u8003<\/a><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-\u8001\u7d2b\u7af9\u7684\u5bb6 wp-block-embed-\u8001\u7d2b\u7af9\u7684\u5bb6\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"03vhEjtkZ0\"><a href=\"https:\/\/www.gbase8.cn\/en\/2618\/\">GBase 8a OLAP\u5206\u6790\u51fd\u6570group by rollup\u4f7f\u7528\u6837\u4f8b<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"\u300aGBase 8a OLAP\u5206\u6790\u51fd\u6570group by rollup\u4f7f\u7528\u6837\u4f8b\u300b\u2014\u8001\u7d2b\u7af9\u7684\u5bb6\" src=\"https:\/\/www.gbase8.cn\/2618\/embed#?secret=03vhEjtkZ0\" data-secret=\"03vhEjtkZ0\" width=\"600\" height=\"338\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>","protected":false},"excerpt":{"rendered":"<p>\u5357\u5927\u901a\u7528GBase 8a\u7684group grouping sets\u529f\u80fd,\u5bf9\u540e\u9762\u62ec\u53f7\u91cc\u7684 n \u4e2a\u5b57\u6bb5\u6216\u8868\u8fbe\u5f0f\u5206\u522b\u505a GROUP BY \u64cd\u4f5c\uff0c\u6700\u540e\u5c06\u7ed3\u679c\u5408\u5e76\u5728\u4e00\u8d77\u3002\u7b49\u540c\u4e8e\u591a\u4e2a\u5355\u72ec\u7684group by\u540e\u518d\u505a\u4e00\u4e2aunion all\u64cd\u4f5c\u3002<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[36,77],"class_list":["post-2620","post","type-post","status-publish","format-standard","hentry","category-gbase8a","tag-36","tag-olap"],"_links":{"self":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/2620","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=2620"}],"version-history":[{"count":5,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/2620\/revisions"}],"predecessor-version":[{"id":6777,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/2620\/revisions\/6777"}],"wp:attachment":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/media?parent=2620"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/categories?post=2620"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/tags?post=2620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}