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/