I have a table with CustomerID and ArrivalDateTime (datetime). I would like to calculate the occurrence of the CutomerID within the last 7 days of each Arrival Date.
I came up with the below SQL statement however it is not working.
Can someone help me what I am doing wrong?
Thanks
SELECT d1.DateValue,
cr1.CustomerID,
COUNT(ISNULL(cr2.CustomerID,0)) as [No_of_presentation]
FROM [dbo].[CustomerPresentation] cr1 join DimDate d1 on d1.DateValue = cr1.Arrivaldate
Left JOIN [dbo].[CustomerPresentation] cr2 ON cr1.CustomerID = cr2.CustomerID
join DimDate d2 on d2.DateValue= cr2.ArrivalDate
WHERE (d1.DateValue BETWEEN DATEADD(dd,-7,d2.DateValue) AND d2.DateValue)
GROUP BY d1.DateValue, cr1.CustomerID