有一个表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