当前位置:数据库 > Oracle >>

ORACLE分析函数-WIDTH-BUCKET

ORACLE分析函数-WIDTH-BUCKET
 
        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] 
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] 
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  

 


Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,