ID input_date created
22564 3/4/2019 5/29/2019
22564 3/4/2019 3/6/2019
22564 3/4/2019 3/12/2019
22564 3/4/2019 4/18/2019
22564 3/4/2019 4/12/2019
22564 3/4/2019 4/10/2019
22564 3/4/2019 3/25/2019
22564 3/4/2019 3/29/2019
22564 3/4/2019 4/4/2019
22564 3/4/2019 3/19/2019
22564 3/4/2019 5/29/2019
22564 3/4/2019 5/20/2019
22543 3/4/2019 3/20/2019
22543 3/4/2019 3/28/2019
22543 3/4/2019 4/12/2019
22543 3/4/2019 4/19/2019
22543 3/4/2019 3/13/2019
22543 3/4/2019 3/6/2019
22543 3/4/2019 5/20/2019
22543 3/4/2019 6/17/2019
22543 3/4/2019 4/4/2019
12558 3/4/2019 1/4/2019
I want to get this first
acctrefno first second third fourth
22564 2 8 15 21
22543 2 9 16 24
22595 2 9 16 24
24324 1 7 12 19
26506 1 12 20 26
Finally, I would like to get here i.e.
- if the first is within the 3 days from date input I want to pit 1
- if second is withing 3 days from first then I want to put 1
- else 0 and so on till the fourth date.
Etc...
acctrefno first second third fourth
22564 1 0 0 0
22543 1 0 0 0
22595 1 0 0 0
24324 1 0 0 0
26506 1 0 0 0
I have completed this in excel and Tableau but its very time consuming and I have a large data set so I need to do it in SQL
Do not have a code as I did not try thin in SQL I have no clue how to go about it. The only thing I can do is use datediff
function and come up with days
NA