ORACLE分析函數(8) WIDTH-BUCKET

來源:互聯網
上載者:User

WIDTH-BUCKET會根據參數設定,返回目前記錄所屬的bucket number。文法格式如下:

      WIDTH_BUCKET(expression, minval expression, maxval expression, num buckets)

       第一個參數,為某數字或者日期運算式;第二個參數為某範圍的下限;第三個參數為某範圍的上限;第四個參數為對某範圍進行等值劃分bucket的數量。如

WIDTH_BUCKET(expression, 0, 2000, 4),會劃分4個bucket,其範圍為【0,500)【500,100)【1000,1500)【1500,2000)。如果我們指定EXPRESSION 值為300,則width_bucker 返回1,以此類推。如果express的值小於0,則返回0;如果expression大於或者等於2000,則返回5.

SQL> select cust_credit_limit,width_bucket(cust_credit_limit,0,15000,3) from customers where rownum < 15;        CUST_CREDIT_LIMIT WIDTH_BUCKET(CUST_CREDIT_LIMIT,0,15000,3)  ----------------- -----------------------------------------               1500                                         1               7000                                         2              11000                                         3               1500                                         1               9000                                         2               9000                                         2               3000                                         1               7000                                         2              11000                                         3               1500                                         1               9000                                         2              15000                                         4              11000                                         3               7000                                         2

如果,第一個參數為null,則返回null

SQL> select cust_credit_limit,width_bucket(case when cust_credit_limit<2000 then null else cust_credit_limit end,0,15000,3) wb from customers where rownum < 15;        CUST_CREDIT_LIMIT         WB  ----------------- ----------               1500               7000          2              11000          3               1500               9000          2               9000          2               3000          1               7000          2              11000          3               1500               9000          2              15000          4              11000          3               7000          2

查看本欄目更多精彩內容:http://www.bianceng.cnhttp://www.bianceng.cn/database/Oracle/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.