---最大连续交易天数
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('', '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('', '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('', '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('', 'yyyymmdd')
group by ctd.customer_no)t4 on t3.customer_no = t4.customer_no
group by t3.ypc

Oracle-利用解析函数计算连续、回流的更多相关文章

  1. Oracle计算连续天数,计算连续时间,Oracle连续天数统计

    Oracle计算连续天数,计算连续时间,Oracle连续天数统计 >>>>>>>>>>>>>>>>> ...

  2. mysql计算连续天数,mysql连续登录天数,连续天数统计

    mysql计算连续天数,mysql连续登录天数,连续天数统计 >>>>>>>>>>>>>>>>>& ...

  3. 虚拟机VMWARE上ORACLE License 的计算

    Oracle License的计算有两种方式:按照用户数和CPU个数. 其中按CPU计算方式如下: License Number = The Number of CPU Cores  *  Core ...

  4. oracle 利用flashback将备库激活为read wirte(10g 及上)

    oracle 利用flashback将备库激活为read wirte(10g 及上) 环境: OS: CENTOS 6.5 X64 DB: ORACLE 10.2.0.5 主库操作: SQL> ...

  5. 利用sklearn计算文本相似性

    利用sklearn计算文本相似性,并将文本之间的相似度矩阵保存到文件当中.这里提取文本TF-IDF特征值进行文本的相似性计算. #!/usr/bin/python # -*- coding: utf- ...

  6. 计算连续的IP地址

    题目:要求计算连续的IP地址. 举例:起始IP为192.168.2.2,IP总个数为3,那么要求得的所有IP的为192.168.2.2,192.168.2.3,192.168.2.4.再举个例子,起始 ...

  7. 利用Python计算π的值,并显示进度条

    利用Python计算π的值,并显示进度条  第一步:下载tqdm 第二步;编写代码 from math import * from tqdm import tqdm from time import ...

  8. Ajax实例一:利用服务器计算

    Ajax实例一:利用服务器计算 HTML代码 //输入两个数 <input id="number1" type="number"> <inpu ...

  9. 利用函数计算构建微信小程序的Server端

    10分钟上线 - 利用函数计算构建微信小程序的Server端-博客-云栖社区-阿里云 https://yq.aliyun.com/articles/435430 函数计算  读写 oss import ...

随机推荐

  1. springmvc 下载excel

    jsp: controller:

  2. css的优先级和权重问题 以及!important优先级

    一,前言: 刚加的css怎么没有渲染出来?浏览器中查看,发现是被其他的css给覆盖了,相信我们都曾遇到过这样的问题.那么浏览器是如何选择css标签的渲染顺序的呢?换句话说,css选择器的优先级是怎么规 ...

  3. Openssl base64命令

    一.简介 对文件件进行base64的编码与解码 二.语法 openssl base64 [-in filename] [-out filename] 三.实例 1.二进制文件与base64编码互转 o ...

  4. Native2Ascii文件转换 -- 待完善

    摘自:https://www.oschina.net/code/snippet_87799_1612 Native2Ascii文件转换 -- 待完善 package com.xxx.xxx.Util; ...

  5. zigbee广播通信原理

    广播:可以理解成,发送模块发出数据,这个网络里的所有节点模块都可以拿到这个数据. 实验:终端模块以广播的形式发送出去,让协调器和路由器模块作为接收器收到数据并显示出来! 协调器模块作为接收模块: 和单 ...

  6. mysql 存储过程学习(总)

    #一.存储过程和存储函数的创建案例 CREATE PROCEDURE myprocedure(in a int,in b int ,OUT c INT) BEGIN set c=a+b; end; c ...

  7. POC索引

    最近在看窗口函数,接触到了POC索引,所以借此机会好好研究一下索引. 一般支持窗口函数的索引指南都遵循POC的概念,也就是Partitioning(分区).Ordering(排序)和Covering( ...

  8. libxml2

    http://www.xmlsoft.org/downloads.html   建议直接用openscenegraph下载的3rdparty:http://www.openscenegraph.org ...

  9. HDU 4756 Install Air Conditioning (MST+树形DP)

    题意:n-1个宿舍,1个供电站,n个位置每两个位置都有边相连,其中有一条边不能连,求n个位置连通的最小花费的最大值. 析:因为要连通,还要权值最小,所以就是MST了,然后就是改变一条边,然后去找出改变 ...

  10. 编写高质量代码改善C#程序的157个建议——建议117:使用SSL确保通信中的数据安全

    建议117:使用SSL确保通信中的数据安全 SSL(Secure Socket Layer)最初是由NetScape公司设计的,用于Web安全的网络协议.目前它已经广泛应用到各类网络传输通信中了.SS ...