{"id":2618,"date":"2020-12-29T13:29:36","date_gmt":"2020-12-29T05:29:36","guid":{"rendered":"https:\/\/www.gbase8.cn\/?p=2618"},"modified":"2021-06-29T10:24:30","modified_gmt":"2021-06-29T02:24:30","slug":"gbase-8a-olap%e5%88%86%e6%9e%90%e5%87%bd%e6%95%b0group-by-roll-up%e4%bd%bf%e7%94%a8%e6%a0%b7%e4%be%8b","status":"publish","type":"post","link":"https:\/\/www.gbase8.cn\/en\/2618","title":{"rendered":"\u5357\u5927\u901a\u7528GBase 8a OLAP\u5206\u6790\u51fd\u6570group by rollup\u4f7f\u7528\u6837\u4f8b"},"content":{"rendered":"<p>GBase 8a\u7684 group rollup \u51fd\u6570\u901a\u5e38\u7528\u4e8e\u7edf\u8ba1\u4f8b\u5982\u5546\u54c1\u7684\u660e\u7ec6\uff0c\u5c0f\u8ba1\u4ee5\u53ca\u6700\u540e\u603b\u8ba1\u7684\u573a\u666f\u3002\u901a\u8fc7\u5bf9\u4e0d\u540c\u7ec4\u5408\u7684\u8ba1\u7b97\uff0c\u5f97\u5230\u6bcf\u4e2a\u5c42\u6b21\u7684\u8ba1\u7b97\u7ed3\u679c\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-6a2aade6bd5a5\" 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-6a2aade6bd5a5\"  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\/2618\/#%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\/2618\/#%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\/2618\/#%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\/2618\/#%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\/2618\/#%E5%8E%9F%E5%A7%8B%E6%95%B0%E6%8D%AE%E6%98%AF%E5%AD%A6%E7%94%9F%E6%88%90%E7%BB%A9%E5%8D%95%E3%80%82\" >\u539f\u59cb\u6570\u636e\u662f\u5b66\u751f\u6210\u7ee9\u5355\u3002<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.gbase8.cn\/en\/2618\/#%E6%8B%BF%E5%88%B0%E6%AF%8F%E4%B8%AA%E5%AD%A6%E7%94%9F%E6%88%90%E7%BB%A9%E6%80%BB%E5%92%8C\" >\u62ff\u5230\u6bcf\u4e2a\u5b66\u751f\u6210\u7ee9\u603b\u548c<\/a><\/li><\/ul><\/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\/2618\/#%E6%AF%8F%E4%B8%AA%E7%A7%91%E7%9B%AE%E7%9A%84%E6%88%90%E7%BB%A9%E6%80%BB%E5%92%8C\" >\u6bcf\u4e2a\u79d1\u76ee\u7684\u6210\u7ee9\u603b\u548c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.gbase8.cn\/en\/2618\/#%E6%AF%8F%E4%B8%AA%E5%AD%A6%E7%94%9F%EF%BC%8C%E6%AF%8F%E4%B8%AA%E5%AE%A2%E6%88%B7%E7%9A%84%E6%80%BB%E5%92%8C\" >\u6bcf\u4e2a\u5b66\u751f\uff0c\u6bcf\u4e2a\u5ba2\u6237\u7684\u603b\u548c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.gbase8.cn\/en\/2618\/#%E6%AF%8F%E4%B8%AA%E7%A7%91%E7%9B%AE%EF%BC%8C%E6%AF%8F%E4%B8%AA%E5%AD%A6%E7%94%9F%E7%9A%84%E6%88%90%E7%BB%A9%E6%80%BB%E5%92%8C\" >\u6bcf\u4e2a\u79d1\u76ee\uff0c\u6bcf\u4e2a\u5b66\u751f\u7684\u6210\u7ee9\u603b\u548c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.gbase8.cn\/en\/2618\/#%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><\/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<pre class=\"wp-block-code\"><code>GROUP BY ROLLUP( (\u2026),(\u2026),\u2026)<\/code><\/pre>\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 ROLLUP(A,B,C) (A\u3001B\u3001C \u4ee3\u8868\u8bed\u6cd5\u4e2d\u7684\u201c(\u2026)\u201d)<br>\u9996\u5148\u4f1a\u5bf9(A\u3001B\u3001C)\u8fdb\u884c GROUP BY\uff0c\u7136\u540e\u5bf9(A\u3001B)\u8fdb\u884c GROUP BY\uff0c\u7136\u540e\u662f(A)\u8fdb\u884c GROUP BY\uff0c\u7136\u540e\u5bf9\u5168\u8868\u8fdb\u884c GROUP BY \u64cd\u4f5c\uff0c\u6700\u540e\u5c06\u6240\u6709\u7ed3\u679c\u5408\u5e76\u5728\u4e00\u8d77(\u76f8\u5f53\u4e8e UNION ALL \u64cd\u4f5c),\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=\"%E5%8E%9F%E5%A7%8B%E6%95%B0%E6%8D%AE%E6%98%AF%E5%AD%A6%E7%94%9F%E6%88%90%E7%BB%A9%E5%8D%95%E3%80%82\"><\/span>\u539f\u59cb\u6570\u636e\u662f\u5b66\u751f\u6210\u7ee9\u5355\u3002<span class=\"ez-toc-section-end\"><\/span><\/h3>\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.00)\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%8B%BF%E5%88%B0%E6%AF%8F%E4%B8%AA%E5%AD%A6%E7%94%9F%E6%88%90%E7%BB%A9%E6%80%BB%E5%92%8C\"><\/span>\u62ff\u5230\u6bcf\u4e2a\u5b66\u751f\u6210\u7ee9\u603b\u548c<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase&gt; select name,sum(score) from score group by rollup(name);\n+--------+------------+\n| name   | sum(score) |\n+--------+------------+\n| \u738b\u6d77   |        262 |\n| \u9676\u4fca   |        266 |\n| \u5218\u53ef   |        254 |\n| \u674e\u6625   |        256 |\n| NULL   |       1038 |\n+--------+------------+\n5 rows in set (Elapsed: 00:00:00.06)\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%AF%8F%E4%B8%AA%E7%A7%91%E7%9B%AE%E7%9A%84%E6%88%90%E7%BB%A9%E6%80%BB%E5%92%8C\"><\/span>\u6bcf\u4e2a\u79d1\u76ee\u7684\u6210\u7ee9\u603b\u548c<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase&gt; select subject,sum(score) from score group by rollup(subject);\n+---------+------------+\n| subject | sum(score) |\n+---------+------------+\n| \u8bed\u6587    |        343 |\n| \u6570\u5b66    |        333 |\n| \u82f1\u8bed    |        362 |\n| NULL    |       1038 |\n+---------+------------+\n4 rows in set (Elapsed: 00:00:00.01)\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%AF%8F%E4%B8%AA%E5%AD%A6%E7%94%9F%EF%BC%8C%E6%AF%8F%E4%B8%AA%E5%AE%A2%E6%88%B7%E7%9A%84%E6%80%BB%E5%92%8C\"><\/span>\u6bcf\u4e2a\u5b66\u751f\uff0c\u6bcf\u4e2a\u5ba2\u6237\u7684\u603b\u548c<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 rollup(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| NULL   | NULL    |       1038 |\n+--------+---------+------------+\n17 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=\"%E6%AF%8F%E4%B8%AA%E7%A7%91%E7%9B%AE%EF%BC%8C%E6%AF%8F%E4%B8%AA%E5%AD%A6%E7%94%9F%E7%9A%84%E6%88%90%E7%BB%A9%E6%80%BB%E5%92%8C\"><\/span>\u6bcf\u4e2a\u79d1\u76ee\uff0c\u6bcf\u4e2a\u5b66\u751f\u7684\u6210\u7ee9\u603b\u548c<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u8bf7\u6ce8\u610f\u548c\u524d\u9762\u7684\u533a\u5206\uff0c\u8fd9\u4e2a\u5173\u6ce8\u79d1\u76ee\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase&gt; select name,subject,sum(score) from score group by rollup(subject,name);\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| NULL   | \u8bed\u6587    |        343 |\n| NULL   | \u6570\u5b66    |        333 |\n| NULL   | \u82f1\u8bed    |        362 |\n| NULL   | NULL    |       1038 |\n+--------+---------+------------+\n16 rows in set (Elapsed: 00:00:00.02)\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>","protected":false},"excerpt":{"rendered":"<p>\u5357\u5927\u901a\u7528GBase 8a\u7684 group rollup \u51fd\u6570\u901a\u5e38\u7528\u4e8e\u7edf\u8ba1\u4f8b\u5982\u5546\u54c1\u7684\u660e\u7ec6\uff0c\u5c0f\u8ba1\u4ee5\u53ca\u6700\u540e\u603b\u8ba1\u7684\u573a\u666f\u3002\u901a\u8fc7\u5bf9\u4e0d\u540c\u7ec4\u5408\u7684\u8ba1\u7b97\uff0c\u5f97\u5230\u6bcf\u4e2a\u5c42\u6b21\u7684\u8ba1\u7b97\u7ed3\u679c\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-2618","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\/2618","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=2618"}],"version-history":[{"count":4,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/2618\/revisions"}],"predecessor-version":[{"id":6665,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/2618\/revisions\/6665"}],"wp:attachment":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/media?parent=2618"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/categories?post=2618"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/tags?post=2618"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}