{"id":12489,"date":"2023-12-29T15:25:09","date_gmt":"2023-12-29T07:25:09","guid":{"rendered":"https:\/\/www.gbase8.cn\/?p=12489"},"modified":"2023-12-29T15:25:09","modified_gmt":"2023-12-29T07:25:09","slug":"gbase-8a-olap%e5%88%86%e6%9e%90%e5%87%bd%e6%95%b0ntile%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\/12489","title":{"rendered":"\u5357\u5927\u901a\u7528GBase 8a OLAP\u5206\u6790\u51fd\u6570NTILE\u7684\u4f7f\u7528\u6837\u4f8b"},"content":{"rendered":"<p>GBase 8a\u7684NTILE\u51fd\u6570\uff0c\u5c06\u6570\u636e\u5207\u5206\u6210\u6307\u5b9a\u7684\u51e0\u5757\uff0c\u5982\u679c\u4e14\u4e0d\u5747\u5300\uff0c\u5219\u524d\u9762\u7684\u4f18\u5148\u3002\u672c\u6587\u4ecb\u7ecdNTILE\u7684\u7528\u6cd5\u548c\u4f7f\u7528\u6837\u4f8b\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-6a2aa397487b9\" 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-6a2aa397487b9\"  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\/12489\/#%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-2\" href=\"https:\/\/www.gbase8.cn\/en\/12489\/#%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-3\" href=\"https:\/\/www.gbase8.cn\/en\/12489\/#%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-4\" href=\"https:\/\/www.gbase8.cn\/en\/12489\/#%E6%95%B0%E6%8D%AE\" >\u6570\u636e<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.gbase8.cn\/en\/12489\/#%E6%A0%87%E5%87%86NTILE%E7%94%A8%E6%B3%95\" >\u6807\u51c6NTILE\u7528\u6cd5<\/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\/12489\/#%E6%97%A0partition%E7%9A%84NTILE\" >\u65e0partition\u7684NTILE<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.gbase8.cn\/en\/12489\/#%E6%97%A0order%E7%9A%84NTILE\" >\u65e0order\u7684NTILE<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.gbase8.cn\/en\/12489\/#%E6%97%A0Partition%E5%92%8Corder%E7%9A%84NTILE\" >\u65e0Partition\u548corder\u7684NTILE<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\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 has-small-font-size\"><code>NTILE(num) OVER(&#91;PARTITION BY col_name1,col_name2,\u2026] ORDER BY col_name1 &#91;asc\/desc], col_name2 &#91;asc\/desc],\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>num\u53c2\u6570\u662f\u6307\u5b9a\u5207\u6210\u51e0\u5757\u3002 \u7b2c\u4e00\u5757\u503c\u4e3a1\uff0c\u7b2c\u4e8c\u5757\u4e3a2\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u4e00\u4e2a\u7a97\u53e3\u5185\u7684\u6570\u636e\uff0c\u65e0\u6cd5\u5747\u5300\u7684\u5206\u6210\u6307\u5b9a\u5757\u6570\uff0c\u5219\u4f18\u5148\u586b\u5145\u524d\u9762\u7684\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\"><\/span>\u6570\u636e<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>gbase> create table td(id int, type int,val decimal(20,3));\r\nQuery OK, 0 rows affected (Elapsed: 00:00:00.17)\r\n\r\ngbase> insert into td values(1,1,111),(1,1,222),(2,1,333),(2,2,444),(3,2,555),(3,2,666),(4,2,777);\r\nQuery OK, 7 rows affected (Elapsed: 00:00:00.12)\r\nRecords: 7  Duplicates: 0  Warnings: 0\r\n\r\ngbase> insert into td values(5,1,null),(50,2,null);\r\nQuery OK, 2 rows affected (Elapsed: 00:00:00.09)\r\nRecords: 2  Duplicates: 0  Warnings: 0\r\n\r\ngbase> select * from td;\r\n+------+------+---------+\r\ngbase> select * from td order by type;\r\n+------+------+---------+\r\n| id   | type | val     |\r\n+------+------+---------+\r\n|    1 |    1 | 222.000 |\r\n|    2 |    1 | 333.000 |\r\n|    5 |    1 |    NULL |\r\n|    1 |    1 | 111.000 |\r\n|    3 |    2 | 666.000 |\r\n|    4 |    2 | 777.000 |\r\n|    3 |    2 | 555.000 |\r\n|    2 |    2 | 444.000 |\r\n|   50 |    2 |    NULL |\r\n+------+------+---------+\r\n9 rows in set (Elapsed: 00:00:00.04)\r\n\r\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%A0%87%E5%87%86NTILE%E7%94%A8%E6%B3%95\"><\/span>\u6807\u51c6NTILE\u7528\u6cd5<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>type=2\u91cc\u67095\u4e2a\uff0c\u5206\u4e0d\u5747\u5300\uff0c\u5206\u57571\u4e3a3\u4e2a\uff0c\u5206\u57572\u4e3a2\u4e2a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>gbase> select *,ntile(2)over(partition by type order by id) maxOfType from td;\r\n+------+------+---------+-----------+\r\n| id   | type | val     | maxOfType |\r\n+------+------+---------+-----------+\r\n|    1 |    1 | 111.000 |         1 |\r\n|    1 |    1 | 222.000 |         1 |\r\n|    2 |    1 | 333.000 |         2 |\r\n|    2 |    2 | 444.000 |         1 |\r\n|    3 |    2 | 555.000 |         1 |\r\n|    3 |    2 | 666.000 |         1 |\r\n|    4 |    2 | 777.000 |         2 |\r\n|    5 |    1 |    NULL |         2 |\r\n|   50 |    2 |    NULL |         2 |\r\n+------+------+---------+-----------+\r\n9 rows in set (Elapsed: 00:00:00.35)\r\n\r\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%97%A0partition%E7%9A%84NTILE\"><\/span>\u65e0partition\u7684NTILE<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u6240\u6709\u6570\u636e\u5206\u62102\u5757\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>gbase> select *,ntile(2)over(order by id) maxOfType from td;\r\n+------+------+---------+-----------+\r\n| id   | type | val     | maxOfType |\r\n+------+------+---------+-----------+\r\n|    1 |    1 | 111.000 |         1 |\r\n|    1 |    1 | 222.000 |         1 |\r\n|    2 |    1 | 333.000 |         1 |\r\n|    2 |    2 | 444.000 |         1 |\r\n|    3 |    2 | 555.000 |         1 |\r\n|    3 |    2 | 666.000 |         2 |\r\n|    4 |    2 | 777.000 |         2 |\r\n|    5 |    1 |    NULL |         2 |\r\n|   50 |    2 |    NULL |         2 |\r\n+------+------+---------+-----------+\r\n9 rows in set (Elapsed: 00:00:00.08)\r\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%97%A0order%E7%9A%84NTILE\"><\/span>\u65e0order\u7684NTILE<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u81ea\u7136\u987a\u5e8f\uff0c\u4e0d\u4fdd\u8bc1\u6bcf\u6b21\u76f8\u540c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>gbase> select *,ntile(2)over(partition by type) maxOfType from td;\r\n+------+------+---------+-----------+\r\n| id   | type | val     | maxOfType |\r\n+------+------+---------+-----------+\r\n|    1 |    1 | 111.000 |         2 |\r\n|    1 |    1 | 222.000 |         1 |\r\n|    2 |    1 | 333.000 |         1 |\r\n|    2 |    2 | 444.000 |         2 |\r\n|    3 |    2 | 555.000 |         1 |\r\n|    3 |    2 | 666.000 |         1 |\r\n|    4 |    2 | 777.000 |         1 |\r\n|    5 |    1 |    NULL |         2 |\r\n|   50 |    2 |    NULL |         2 |\r\n+------+------+---------+-----------+\r\n9 rows in set (Elapsed: 00:00:00.07)\r\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%97%A0Partition%E5%92%8Corder%E7%9A%84NTILE\"><\/span>\u65e0Partition\u548corder\u7684NTILE<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>gbase> select *,ntile(2)over() maxOfType from td;\r\n+------+------+---------+-----------+\r\n| id   | type | val     | maxOfType |\r\n+------+------+---------+-----------+\r\n|    1 |    1 | 111.000 |         1 |\r\n|    1 |    1 | 222.000 |         1 |\r\n|    2 |    1 | 333.000 |         1 |\r\n|    2 |    2 | 444.000 |         1 |\r\n|    3 |    2 | 555.000 |         1 |\r\n|    3 |    2 | 666.000 |         2 |\r\n|    4 |    2 | 777.000 |         2 |\r\n|    5 |    1 |    NULL |         2 |\r\n|   50 |    2 |    NULL |         2 |\r\n+------+------+---------+-----------+\r\n9 rows in set (Elapsed: 00:00:00.29)\r\n<\/code><\/pre>","protected":false},"excerpt":{"rendered":"<p>\u5357\u5927\u901a\u7528GBase 8a\u7684NTILE\u51fd\u6570\uff0c\u5c06\u6570\u636e\u5207\u5206\u6210\u6307\u5b9a\u7684\u51e0\u5757\uff0c\u5982\u679c\u4e14\u4e0d\u5747\u5300\uff0c\u5219\u524d\u9762\u7684\u4f18\u5148\u3002\u672c\u6587\u4ecb\u7ecdNTILE\u7684\u7528\u6cd5\u548c\u4f7f\u7528\u6837\u4f8b\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-12489","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\/12489","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=12489"}],"version-history":[{"count":1,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/12489\/revisions"}],"predecessor-version":[{"id":12490,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/12489\/revisions\/12490"}],"wp:attachment":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/media?parent=12489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/categories?post=12489"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/tags?post=12489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}