Now have a data below
I want to calculate the time difference between two customers under the same ID (in) the absolute value of, how can I write ah, thanked first here,
CodePudding user response:
WITH CTE
AS
(SELECT *, Row_Number () OVER (partition by ID ORDER by DT ASC) rank the FROM dbo. Customer)
SELECT Anderson D, DATEDIFF (MONTH, a. d. T, b.D T) FROM CTE JOIN a CTE ON Anderson, D=b b.I D AND a.r ank=b.r ank - 1
CodePudding user response:
Thank you for big grant instruction