查询任意时间内重复出现的记录

有一个表card
列属性
(1)id
(2)acount //消费金额
(3)asn    //卡号
(4)consumtime //消费时间

我想查找,任意10分钟之内,找到同一张卡,消费金额相同的信息(就是同一张卡在十分钟之内消费了相同的金额)
输出卡号和消费信息以及消费时间
我之前写的是这样,我随便查找了一个日期

 

with card as(
  select '1' id, 19 account,'0001' asn,to_date('2009-01-02 12:16:23','yyyy-mm-dd hh24:mi:ss') consumtime from dual
  union all
  select '2' id, 20 account,'0002' asn,to_date('2009-01-02 12:14:23','yyyy-mm-dd hh24:mi:ss') consumticme from dual
  union all
  select '3' id, 19 account,'0001' asn,to_date('2009-01-02 12:15:23','yyyy-mm-dd hh24:mi:ss') consumtime from dual
  union all
  select '4' id, 20 account,'0002' asn,to_date('2009-01-02 12:27:23','yyyy-mm-dd hh24:mi:ss') consumtime from dual
  union all
  select '5' id, 17 account,'0003' asn,to_date('2009-01-02 12:11:23','yyyy-mm-dd hh24:mi:ss') consumtime from dual
  union all
  select '6' id, 15 account,'0002' asn,to_date('2009-01-02 12:17:22','yyyy-mm-dd hh24:mi:ss') consumtime from dual 
  union all
    select '4' id, 20 account,'0002' asn,to_date('2009-01-02 12:32:23','yyyy-mm-dd hh24:mi:ss') consumtime from dual
)

select * from (
select c1.id,c1.account,c1.asn,c1.consumtime,
lead(consumtime) over(partition by c1.asn,c1.account order by consumtime) nextconsumtime from card c1,
(
select account,asn from card group by account,asn having count(asn) > 1
) c2 where c1.account = c2.account and c1.asn = c2.asn
) where nextconsumtime is not null and nextconsumtime <= consumtime+1/(24*60)*10

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值