{"id":160215,"date":"2024-11-03T21:14:26","date_gmt":"2024-11-03T13:14:26","guid":{"rendered":"https:\/\/server.hk\/cnblog\/160215\/"},"modified":"2024-11-03T21:14:27","modified_gmt":"2024-11-03T13:14:27","slug":"oceanbase-%e6%95%99%e7%a8%8b%ef%bc%9aoceanbase-rollup","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/160215\/","title":{"rendered":"OceanBase \u6559\u7a0b\uff1aOceanBase ROLLUP"},"content":{"rendered":"<h1 id=\"oceanbase-%e6%95%99%e7%a8%8b%ef%bc%9aoceanbase-rollup-PDJZIfvcyx\">OceanBase \u6559\u7a0b\uff1aOceanBase ROLLUP<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u5eab\u6280\u8853\u4e2d\uff0cOceanBase \u4f5c\u70ba\u4e00\u500b\u9ad8\u6027\u80fd\u7684\u5206\u4f48\u5f0f\u6578\u64da\u5eab\u7cfb\u7d71\uff0c\u8d8a\u4f86\u8d8a\u53d7\u5230\u95dc\u6ce8\u3002\u5b83\u7531\u963f\u91cc\u5df4\u5df4\u96c6\u5718\u958b\u767c\uff0c\u65e8\u5728\u652f\u6301\u5927\u898f\u6a21\u7684\u5728\u7dda\u4ea4\u6613\u8655\u7406\uff08OLTP\uff09\u548c\u5728\u7dda\u5206\u6790\u8655\u7406\uff08OLAP\uff09\u3002\u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5011\u5c07\u6df1\u5165\u63a2\u8a0e OceanBase \u7684 ROLLUP \u529f\u80fd\uff0c\u9019\u662f\u4e00\u500b\u5f37\u5927\u7684\u6578\u64da\u805a\u5408\u5de5\u5177\uff0c\u80fd\u5920\u5e6b\u52a9\u7528\u6236\u66f4\u9ad8\u6548\u5730\u9032\u884c\u6578\u64da\u5206\u6790\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-rollup%ef%bc%9f-PDJZIfvcyx\">\u4ec0\u9ebc\u662f ROLLUP\uff1f<\/h2>\n<p>ROLLUP \u662f\u4e00\u7a2e SQL \u805a\u5408\u529f\u80fd\uff0c\u4e3b\u8981\u7528\u65bc\u751f\u6210\u5c0f\u8a08\u548c\u7e3d\u8a08\u3002\u5b83\u53ef\u4ee5\u5728 GROUP BY \u67e5\u8a62\u4e2d\u4f7f\u7528\uff0c\u5e6b\u52a9\u7528\u6236\u5728\u591a\u7dad\u6578\u64da\u4e2d\u9032\u884c\u5c64\u6b21\u5316\u7684\u805a\u5408\u3002\u4f7f\u7528 ROLLUP\uff0c\u60a8\u53ef\u4ee5\u5728\u4e00\u500b\u67e5\u8a62\u4e2d\u7372\u5f97\u591a\u500b\u5c64\u6b21\u7684\u805a\u5408\u7d50\u679c\uff0c\u9019\u5c0d\u65bc\u5831\u544a\u548c\u6578\u64da\u5206\u6790\u975e\u5e38\u6709\u7528\u3002<\/p>\n<h2 id=\"oceanbase-%e4%b8%ad%e7%9a%84-rollup-%e8%aa%9e%e6%b3%95-PDJZIfvcyx\">OceanBase \u4e2d\u7684 ROLLUP \u8a9e\u6cd5<\/h2>\n<p>\u5728 OceanBase \u4e2d\uff0cROLLUP \u7684\u8a9e\u6cd5\u8207\u6a19\u6e96 SQL \u985e\u4f3c\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u57fa\u672c\u7684 ROLLUP \u8a9e\u6cd5\u793a\u4f8b\uff1a<\/p>\n<pre><code>SELECT column1, column2, SUM(column3)\nFROM table_name\nGROUP BY ROLLUP(column1, column2);<\/code><\/pre>\n<p>\u5728\u9019\u500b\u67e5\u8a62\u4e2d\uff0c\u60a8\u5c07\u6839\u64da column1 \u548c column2 \u9032\u884c\u5206\u7d44\uff0c\u4e26\u8a08\u7b97 column3 \u7684\u7e3d\u548c\u3002ROLLUP \u5c07\u81ea\u52d5\u751f\u6210\u5c0f\u8a08\u548c\u7e3d\u8a08\u3002<\/p>\n<h2 id=\"%e4%bd%bf%e7%94%a8-rollup-%e7%9a%84%e5%af%a6%e9%9a%9b%e7%af%84%e4%be%8b-PDJZIfvcyx\">\u4f7f\u7528 ROLLUP \u7684\u5be6\u969b\u7bc4\u4f8b<\/h2>\n<p>\u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b\u92b7\u552e\u6578\u64da\u8868\uff0c\u5305\u542b\u4ee5\u4e0b\u5b57\u6bb5\uff1a\u5730\u5340\uff08region\uff09\u3001\u7522\u54c1\uff08product\uff09\u548c\u92b7\u552e\u984d\uff08sales\uff09\u3002\u6211\u5011\u5e0c\u671b\u7372\u5f97\u6bcf\u500b\u5730\u5340\u548c\u7522\u54c1\u7684\u92b7\u552e\u7e3d\u984d\uff0c\u4ee5\u53ca\u6bcf\u500b\u5730\u5340\u7684\u92b7\u552e\u5c0f\u8a08\u548c\u7e3d\u8a08\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8a62\uff1a<\/p>\n<pre><code>SELECT region, product, SUM(sales) AS total_sales\nFROM sales_data\nGROUP BY ROLLUP(region, product);<\/code><\/pre>\n<p>\u9019\u500b\u67e5\u8a62\u5c07\u8fd4\u56de\u6bcf\u500b\u5730\u5340\u548c\u7522\u54c1\u7684\u92b7\u552e\u7e3d\u984d\uff0c\u4e26\u5728\u6bcf\u500b\u5730\u5340\u7684\u6700\u5f8c\u4e00\u884c\u986f\u793a\u8a72\u5730\u5340\u7684\u92b7\u552e\u5c0f\u8a08\uff0c\u6700\u7d42\u9084\u6703\u986f\u793a\u6240\u6709\u5730\u5340\u7684\u92b7\u552e\u7e3d\u8a08\u3002<\/p>\n<h2 id=\"rollup-%e7%9a%84%e5%84%aa%e5%8b%a2-PDJZIfvcyx\">ROLLUP \u7684\u512a\u52e2<\/h2>\n<ul>\n<li><strong>\u7c21\u5316\u67e5\u8a62\uff1a<\/strong>\u4f7f\u7528 ROLLUP\uff0c\u60a8\u53ef\u4ee5\u5728\u4e00\u500b\u67e5\u8a62\u4e2d\u7372\u5f97\u591a\u500b\u5c64\u6b21\u7684\u805a\u5408\u7d50\u679c\uff0c\u9019\u6a23\u53ef\u4ee5\u6e1b\u5c11\u67e5\u8a62\u7684\u8907\u96dc\u6027\u3002<\/li>\n<li><strong>\u63d0\u9ad8\u6027\u80fd\uff1a<\/strong>\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u4f7f\u7528 ROLLUP \u53ef\u4ee5\u63d0\u9ad8\u67e5\u8a62\u6027\u80fd\uff0c\u56e0\u70ba\u6578\u64da\u5eab\u53ef\u4ee5\u512a\u5316\u805a\u5408\u904e\u7a0b\u3002<\/li>\n<li><strong>\u9748\u6d3b\u6027\uff1a<\/strong>ROLLUP \u5141\u8a31\u7528\u6236\u6839\u64da\u9700\u8981\u9032\u884c\u591a\u7dad\u6578\u64da\u5206\u6790\uff0c\u9019\u5c0d\u65bc\u5546\u696d\u667a\u80fd\u548c\u5831\u544a\u975e\u5e38\u91cd\u8981\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-PDJZIfvcyx\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u96d6\u7136 ROLLUP \u63d0\u4f9b\u4e86\u8a31\u591a\u512a\u52e2\uff0c\u4f46\u5728\u4f7f\u7528\u6642\u4e5f\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u5e7e\u9ede\uff1a<\/p>\n<ul>\n<li>ROLLUP \u53ef\u80fd\u6703\u589e\u52a0\u67e5\u8a62\u7684\u8a08\u7b97\u8ca0\u64d4\uff0c\u7279\u5225\u662f\u5728\u8655\u7406\u5927\u91cf\u6578\u64da\u6642\u3002<\/li>\n<li>\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0cROLLUP \u7684\u7d50\u679c\u53ef\u80fd\u6703\u5c0e\u81f4\u6578\u64da\u7684\u91cd\u8907\u6216\u4e0d\u4e00\u81f4\uff0c\u56e0\u6b64\u9700\u8981\u4ed4\u7d30\u6aa2\u67e5\u7d50\u679c\u3002<\/li>\n<li>\u78ba\u4fdd\u5728\u4f7f\u7528 ROLLUP \u6642\uff0c\u5c0d\u65bc NULL \u503c\u7684\u8655\u7406\u65b9\u5f0f\u7b26\u5408\u696d\u52d9\u9700\u6c42\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-PDJZIfvcyx\">\u7e3d\u7d50<\/h2>\n<p>OceanBase \u7684 ROLLUP \u529f\u80fd\u662f\u4e00\u500b\u5f37\u5927\u7684\u5de5\u5177\uff0c\u80fd\u5920\u5e6b\u52a9\u7528\u6236\u5728\u6578\u64da\u5206\u6790\u4e2d\u7372\u5f97\u66f4\u6df1\u5165\u7684\u898b\u89e3\u3002\u901a\u904e\u7c21\u5316\u67e5\u8a62\u548c\u63d0\u9ad8\u6027\u80fd\uff0cROLLUP \u4f7f\u5f97\u591a\u7dad\u6578\u64da\u5206\u6790\u8b8a\u5f97\u66f4\u52a0\u9ad8\u6548\u3002\u5c0d\u65bc\u9700\u8981\u9032\u884c\u8907\u96dc\u5831\u544a\u548c\u6578\u64da\u5206\u6790\u7684\u7528\u6236\u4f86\u8aaa\uff0c\u638c\u63e1 ROLLUP \u7684\u4f7f\u7528\u5c07\u662f\u975e\u5e38\u6709\u76ca\u7684\u3002<\/p>\n<p>\u5982\u679c\u60a8\u5c0d\u65bc <a href=\"https:\/\/server.hk\">\u9999\u6e2f VPS<\/a> \u670d\u52d9\u611f\u8208\u8da3\uff0c\u6216\u60f3\u4e86\u89e3\u66f4\u591a\u95dc\u65bc <a href=\"https:\/\/server.hk\">\u96f2\u4f3a\u670d\u5668<\/a> \u7684\u8cc7\u8a0a\uff0c\u6b61\u8fce\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u8a73\u7d30\u8cc7\u6599\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b66\u4e60\u5982\u4f55\u4f7f\u7528 OceanBase ROLLUP \u529f\u80fd\uff0c\u4f18\u5316\u6570\u636e\u805a\u5408\u548c\u5206\u6790\uff0c\u63d0\u9ad8\u6570\u636e\u5e93\u6027\u80fd\u548c\u6548\u7387\u7684\u5b9e\u7528\u6559\u7a0b\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-160215","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/160215","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=160215"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/160215\/revisions"}],"predecessor-version":[{"id":160216,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/160215\/revisions\/160216"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=160215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=160215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=160215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}