{"id":8985,"date":"2022-03-28T10:05:45","date_gmt":"2022-03-28T02:05:45","guid":{"rendered":"https:\/\/www.gbase8.cn\/?p=8985"},"modified":"2022-06-10T10:52:18","modified_gmt":"2022-06-10T02:52:18","slug":"gbase-8a-olap%e5%88%86%e6%9e%90%e5%87%bd%e6%95%b0cume_dist%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\/8985","title":{"rendered":"\u5357\u5927\u901a\u7528GBase 8a OLAP\u5206\u6790\u51fd\u6570cume_dist\u7684\u4f7f\u7528\u6837\u4f8b"},"content":{"rendered":"\n<p>GBase 8a\u652f\u6301cume_dist \u51fd\u6570\uff0c\u7528\u4e8e\u8ba1\u7b97\u5c0f\u4e8e\u7b49\u4e8e\u6216\u8005\u5927\u4e8e\u7b49\u4e8e(\u6839\u636eorder\u7684\u987a\u5e8f)\u8be5\u503c\u7684\u767e\u5206\u6bd4\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\">\u76ee\u5f55\u5bfc\u822a<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2b3d14caf3c\" 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-6a2b3d14caf3c\"  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\/8985\/#%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\/8985\/#%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\/8985\/#%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\/8985\/#%E5%B0%8F%E4%BA%8E%E7%AD%89%E4%BA%8E\" >\u5c0f\u4e8e\u7b49\u4e8e<\/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\/8985\/#%E5%A4%A7%E4%BA%8E%E7%AD%89%E4%BA%8E\" >\u5927\u4e8e\u7b49\u4e8e<\/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\/8985\/#%E5%B8%A6%E5%BC%80%E7%AA%97partition\" >\u5e26\u5f00\u7a97partition<\/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\/8985\/#%E4%B8%8EPercent_rank%E7%9A%84%E5%AF%B9%E6%AF%94\" >\u4e0ePercent_rank\u7684\u5bf9\u6bd4<\/a><\/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<p>cume_disk() over([partition by ] order by [desc])<\/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>\u5176\u4e2dpartition\u662f\u5426\u5f00\u7a97\uff0c\u5426\u5219\u5168\u90e8\u6570\u503c\u7edf\u4e00\u5904\u7406\u3002<\/p>\n\n\n\n<p>order by \u7684\u987a\u5e8f\uff0cASC\uff08\u9ed8\u8ba4) = \u5c0f\u4e8e\u7b49\u4e8e\uff0cDESC =\u5927\u4e8e\u7b49\u4e8e<\/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%B0%8F%E4%BA%8E%E7%AD%89%E4%BA%8E\"><\/span>\u5c0f\u4e8e\u7b49\u4e8e<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u5982\u4e0b\u4f8b\u5b50\u662f\u9ed8\u8ba4\u7684\u5347\u5e8f\uff0c\u7b2c\u4e00\u884c\u8868\u793a\uff1a\u5c0f\u4e8e\u7b49\u4e8e\u6570\u503c1\u7684\u884c\u6570\u6bd4\u4f8b\u4e3a20%<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase&gt; select id,cume_dist()over(order by id) cr from t2;\n+------+-----+\n| id   | cr  |\n+------+-----+\n|    1 | 0.2 |\n|    2 | 0.4 |\n|    3 | 0.6 |\n|    4 | 0.8 |\n|    5 |   1 |\n+------+-----+\n5 rows in set (Elapsed: 00:00:00.01)\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%A4%A7%E4%BA%8E%E7%AD%89%E4%BA%8E\"><\/span>\u5927\u4e8e\u7b49\u4e8e<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u6392\u5e8f\u4e3adesc\uff0c\u7b2c\u4e00\u884c\u8868\u793a\uff1a\u5927\u4e8e\u7b49\u4e8e\u6570\u503c5\u7684\u884c\u6570\u6bd4\u4f8b\u4e3a20%\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase&gt; select id,cume_dist()over(order by id desc) cr from t2;\n+------+-----+\n| id   | cr  |\n+------+-----+\n|    5 | 0.2 |\n|    4 | 0.4 |\n|    3 | 0.6 |\n|    2 | 0.8 |\n|    1 |   1 |\n+------+-----+\n5 rows in set (Elapsed: 00:00:00.02)\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%B8%A6%E5%BC%80%E7%AA%97partition\"><\/span>\u5e26\u5f00\u7a97partition<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u6bcf\u4e2apartition\u5185\u4e0d\u5206\u522b\u8ba1\u7b97\u767e\u5206\u6bd4\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase&gt; select * from t4;\n+------+------+\n| id   | type |\n+------+------+\n|    1 | A    |\n|    2 | A    |\n|    3 | A    |\n|    1 | B    |\n|    2 | B    |\n|    3 | B    |\n|    4 | B    |\n+------+------+\n7 rows in set (Elapsed: 00:00:00.00)\n\ngbase&gt; select type,id,cume_dist()over(partition by type order by id) cr from t4;\n+------+------+-------------------+\n| type | id   | cr                |\n+------+------+-------------------+\n| A    |    1 | 0.333333333333333 |\n| A    |    2 | 0.666666666666667 |\n| A    |    3 |                 1 |\n| B    |    1 |              0.25 |\n| B    |    2 |               0.5 |\n| B    |    3 |              0.75 |\n| B    |    4 |                 1 |\n+------+------+-------------------+\n7 rows in set (Elapsed: 00:00:00.07)\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E4%B8%8EPercent_rank%E7%9A%84%E5%AF%B9%E6%AF%94\"><\/span>\u4e0ePercent_rank\u7684\u5bf9\u6bd4<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>percent_rank\u662f\u8ba1\u7b97\u76f8\u5bf9\u4f4d\u7f6e\uff0c\u5305\u542b\u8d77\u70b90\uff0c\u800ccume_dist\u662f\u5305\u542b\u7b49\u4e8e\u7684\uff0c\u6240\u4ee5\u4e0d\u4f1a\u51fa\u73b00\u3002\u5982\u679c\u6570\u636e\u53ea\u67091\u884c\uff0c\u90a3\u4e48percent_rank\u4e3a<\/p>\n\n\n\n<p>\u8d77\u70b90\uff0c \u800ccume_dist\u4e3a1\uff08100%\uff09\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase&gt; select id,cume_dist()over(order by id) cr,percent_rank()over(order by id) pr  from t2;\n+------+-----+------+\n| id   | cr  | pr   |\n+------+-----+------+\n|    1 | 0.2 |    0 |\n|    2 | 0.4 | 0.25 |\n|    3 | 0.6 |  0.5 |\n|    4 | 0.8 | 0.75 |\n|    5 |   1 |    1 |\n+------+-----+------+\n5 rows in set (Elapsed: 00:00:00.01)\n<\/code><\/pre>\n\n\n\n<p>\u4e00\u884c\u6570\u636e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase&gt; select id,cume_dist()over(order by id) cr,percent_rank()over(order by id) pr  from t5;\n+------+----+----+\n| id   | cr | pr |\n+------+----+----+\n|    1 |  1 |  0 |\n+------+----+----+\n1 row in set (Elapsed: 00:00:00.02)\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5357\u5927\u901a\u7528GBase 8a\u652f\u6301cume_dist \u51fd\u6570\uff0c\u7528\u4e8e\u8ba1\u7b97\u5c0f\u4e8e\u7b49\u4e8e\u6216\u8005\u5927\u4e8e\u7b49\u4e8e(\u6839\u636eorder\u7684\u987a\u5e8f)\u8be5\u503c\u7684\u767e\u5206\u6bd4\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-8985","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\/8985","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=8985"}],"version-history":[{"count":4,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/8985\/revisions"}],"predecessor-version":[{"id":9626,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/8985\/revisions\/9626"}],"wp:attachment":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/media?parent=8985"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/categories?post=8985"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/tags?post=8985"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}