We help IT Professionals succeed at work.
Get Started

Trying to develop a query in SQL which finds the time frame between two dates with added criteria

355 Views
Last Modified: 2021-04-21
Ok  I want to find the number of days between a cancellation and purchase without including repeat cancellations...

So if new customer then initial value for purchase history = A
If they looked at data put it in cart and no purchase = B
Purchase = C

So I want to get the following data from a pattern

new customer       A
1-Jan-14                     C
2-Jan-14                     B
3-Jan-14                     C
4-Jan-14                 C
5-Jan-14                     B
6-Jan-14                     C
7-Jan-14                     B
8-Jan-14                     B
9-Jan-14                     B
10-Jan-14                     C

So I would like to know the results of days between every instance of B if it follows a C or A. Without getting results for any B which follows a B.

IE the January 7 B had a C appointment three days later.
I would get no results from the Jan 8 or 9th B.
Comment
Watch Question
EE Topic Advisor
CERTIFIED EXPERT
Most Valuable Expert 2014
Awarded 2013
Commented:
This problem has been solved!
Unlock 2 Answers and 4 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE