Hi everyone. I am looking to compare dates in SQL - do a bit of arithmetic on them. What I have is:
Two events - Buying a car, and Servicing the car. I am interested in the people who have had to take their car in for a service within one month of buying their car. So the code I have is:
Code:
SELECT * FROM
(SELECT DISTINCT Customer, Event_type, Event_date
FROM Database
WHERE EVENT_type = "Purchase") A
INNER JOIN
(SELECT DISTINCT Customer, Event_type, Event_date
FROM Database
WHERE EVENT_type = "Service") B
-- bit of code I am struggling with below
WHERE B.Event_date - A.Event_date BETWEEN '1' AND '30'
So my logic is that if the service date - the purchase date is between 1 and 30, then they have taken their car in for a service within the first 30 days of having it.
Any help with that last line of code?
Thanks in advance!