Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding Repeat Records within 72 Hours

Status
Not open for further replies.

EBox

Programmer
Dec 5, 2001
70
0
0
US
Hello:

I am trying to find a way to write an Oracle query (11g) that finds repeat customers transaction purchases that occur within 72 hours of each other. Specifically, if a customer does a transaction on Day 1, and then again on Day 2, I would like to have a query that will pull the transaction record from Day 2.

My table DAILYTABLE captures records for transactions by customers and has timestamps for the transaction completion time (DISCHARGE_TS). I would like to look for repeat customer transactions by EITHER a) CUSTOMER NUMBER or b) CUSTOMER NAME and DOB (sometimes a customer will register again but have an existing customer already and will receive another number, so if we pull by customer name and DOB we will get the repeat transaction), but only if there is a repeat transaction within 72 hours of the DISCHARGE_TS.

Can anyone please help a poor newbie figure this one out?

Many thanks in advance!

E
 
This might give you a start:

SQL> select * from tom;

CUST DTE
---------- ---------
1 01-JAN-15
1 02-JAN-15
1 03-JAN-15
1 07-JAN-15
1 08-JAN-15
1 15-JAN-15
1 17-JAN-15
1 19-JAN-15
1 20-JAN-15

9 rows selected.



SELECT
cust,dte,
COUNT(*) over (partition by cust order by dte range BETWEEN CURRENT row AND interval '3' day following ) cnt,
MAX(dte) over (partition by cust order by dte range BETWEEN CURRENT row AND interval '3' day following ) maxdte
FROM tom

CUST DTE CNT MAXDTE
---------- --------- ---------- ---------
1 01-JAN-15 3 03-JAN-15
1 02-JAN-15 2 03-JAN-15
1 03-JAN-15 1 03-JAN-15
1 07-JAN-15 2 08-JAN-15
1 08-JAN-15 1 08-JAN-15
1 15-JAN-15 2 17-JAN-15
1 17-JAN-15 3 20-JAN-15
1 19-JAN-15 2 20-JAN-15
1 20-JAN-15 1 20-JAN-15

9 rows selected.

In order to understand recursion, you must first understand recursion.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top