读书笔记----WIDTH_BUCKET用法

 
SELECT customer_id, cust_last_name, credit_limit, 
   WIDTH_BUCKET(credit_limit, 100, 5000, 10) "Credit Group"
   FROM customers WHERE nls_territory = 'SWITZERLAND'
   ORDER BY "Credit Group";
结果:
CUSTOMER_ID CUST_LAST_NAME       CREDIT_LIMIT Credit Group
----------- -------------------- ------------ ------------
        825 Dreyfuss                      500            1
        826 Barkin                        500            1
        853 Palin                         400            1
        827 Siegel                        500            1
        843 Oates                         700            2
        844 Julius                        700            2
        835 Eastwood                     1200            3
        840 Elliott                      1400            3
        842 Stern                        1400            3
        841 Boyer                        1400            3
        837 Stanton                      1200            3
        836 Berenger                     1200            3
        848 Olmos                        1800            4
        849 Kaurusmdki                   1800            4
        851 Brown                        2300            5
        850 Finney                       2300            5
        834 Idle                         3500            7
        847 Streep                       5000           11
 
语法:width_bucket(exp,min_num,max_num,times);
例子解释:credit_limit:要展现的字段
 100:最小范围
 5000:最大范围
 10:在最小范围与最大范围之间分10个等级
如果超过最大范围5000 Credit Group = 10+1(超过一个等级,在本例中就是490),n 个等级以此类推。

你可能感兴趣的:(Oracle读书笔记)