zoukankan      html  css  js  c++  java
  • Oracle-利用解析函数计算连续、回流

    ---最大连续交易天数
    select t2.customer_no,max(t2.co) 
    from 
    (select 
    t1.customer_no,t1.yp-t1.rn rk,count(1) co
      from (select ctd.customer_no,
                   ctd.order_time yp,
                   row_number() over(partition by ctd.customer_no order by ctd.order_time) rn
              from posp_boss.customer_trans_day ctd
              where ctd.order_time >= to_date('20180101', 'yyyymmdd')
              order by ctd.customer_no,ctd.order_time)t1
              group by t1.customer_no,t1.yp-t1.rn)t2
              group by t2.customer_no
    ---计算回流状况
    with t1 as
    (select ctd.customer_no,
                   ctd.order_time yp,
                   row_number() over(partition by ctd.customer_no order by ctd.order_time) rn
              from posp_boss.customer_trans_day ctd
              where ctd.order_time >= to_date('20180101', 'yyyymmdd')
              order by ctd.customer_no,ctd.order_time)
              
              
    select t1.customer_no,max(ceil(t2.yp-t1.yp)) ypc   
    from        
    (select t1.customer_no,t1.yp,t1.rn-1 rm
    from t1) t2
    left join t1 on t1.customer_no = t2.customer_no and t1.rn = t2.rm
    group by t1.customer_no
    ---计算回流涉及天数,商户,交易量
    with t1 as
    (select ctd.customer_no,
                   ctd.order_time yp,
                   row_number() over(partition by ctd.customer_no order by ctd.order_time) rn
              from posp_boss.customer_trans_day ctd
              where ctd.order_time >= to_date('20180101', 'yyyymmdd')
              order by ctd.customer_no,ctd.order_time)
              
    select 
    t3.ypc,
    count(distinct t3.customer_no) mt,
    sum(t4.amt) amount
    from 
    (select t1.customer_no,max(ceil(t2.yp-t1.yp)) ypc   
    from        
    (select t1.customer_no,t1.yp,t1.rn-1 rm
    from t1) t2
    left join t1 on t1.customer_no = t2.customer_no and t1.rn = t2.rm
    group by t1.customer_no)t3
    join 
    (select ctd.customer_no,
              sum(ctd.trans_amount) amt 
              from posp_boss.customer_trans_day ctd
              where ctd.order_time >= to_date('20180101', 'yyyymmdd')
              group by ctd.customer_no)t4 on t3.customer_no = t4.customer_no
    group by t3.ypc
  • 相关阅读:
    apache 虚拟主机配置(根据不同的域名映射到不同网站)
    Tortoise SVN 使用笔记
    Apache 根据不同的端口 映射不同的站点
    jquery 获取当前元素的索引值
    修改ThinkPHP的验证码类
    NetBeans无法使用编码GBK安全地打开该文件
    在win2003下apache2.2无法加载php5apache2_4.dll
    我看软件工程
    PHP函数参数传递(相对于C++的值传递和引用传递)
    Notepad++ 使用正则表达式查找替换字符串
  • 原文地址:https://www.cnblogs.com/daoren/p/10461615.html
Copyright © 2011-2022 走看看