日期:2014-05-17 浏览次数:20789 次
with t as ( select '2012001001' a,'12345678' b,'2012000001' c,'1' d,to_date('20120510162923','yyyymmddhh24miss') e from dual union all select '2012001001','12345678','2012000001','1',to_date('20120510163044','yyyymmddhh24miss') from dual union all select '2012001001','12345678','2012000001','1',to_date('20120510163912','yyyymmddhh24miss')from dual union all select '2012001004','12345678','2012000002','1',to_date('20120510164121','yyyymmddhh24miss')from dual union all select '2012001004','32345678','2012000002','2',to_date('20120510164356','yyyymmddhh24miss')from dual union all select '2012001004','22345678','2012000002','1',to_date('20120510164649','yyyymmddhh24miss')from dual union all select '2012001004','52345678','2012000002','2',to_date('20120510164723','yyyymmddhh24miss')from dual union all select '2012001001','32345678','2012000003','1',to_date('20120510164910','yyyymmddhh24miss')from dual union all select '2012001002','82345678','2012000003','2',to_date('20120510165308','yyyymmddhh24miss')from dual union all select '2012001004','92345678','2012000003','3',to_date('20120510165700','yyyymmddhh24miss')from dual union all select '2012001005','92345678','2012000003','2',to_date('20120510170151','yyyymmddhh24miss')from dual union all select '2012001003','82345678','2012000003','3',to_date('20120510170223','yyyymmddhh24miss') from dual ) select t.* from t where exists( select 1 from t a where t.a=a.a and t.b=a.b and t.d= a.d and abs(t.e-a.e)<=2/(24*60) and abs(t.e-a.e)>0 ) --------------------------------- 2012001001 12345678 2012000001 1 2012-5-10 16:29:23 2012001001 12345678 2012000001 1 2012-5-10 16:30:44
------解决方案--------------------
--这样求出来的是连续两次输入时间的间隔<=2分钟,不知道是不是楼主的要求 select distinct 连锁店编号, 会员卡号, 录入员工号, 录入终端, 录入时间 from tab t1 where exists (select 1 from tab t2 where t1.连锁店编号 = t2.连锁店编号 and t1.会员卡号 = t2.会员卡号 and t1.录入员工号 = t2.录入员工号 and t1.录入终端 = t2.录入终端 and t1.录入时间 <> t2.录入时间 and (t1.录入时间 - t2.录入时间)*24*60 >=-2 and (t1.录入时间 - t2.录入时间)*24*60 <=2