Page 1 of 1

How to calculate the interval of days between dates of the same table but of different records

Posted: 2023-08-05 16:35
by vsandoval
How to calculate the interval of days between dates of the same table but of different records
example.jpg
example.jpg (50.97 KiB) Viewed 4856 times
appgini screen.JPG
appgini screen.JPG (88.63 KiB) Viewed 4856 times
This is my code but it doesn't work for me


SELECT ABS(DATEDIFF(FECHA, LAG(FECHA) OVER (ORDER BY FECHA))) FROM `Clientes`;
WHERE `Clientes`.`ID`='%ID%'


Re: How to calculate the interval of days between dates of the same table but of different records

Posted: 2023-08-18 16:19
by mcvaidas
SELECT DATEDIFF( ( SELECT MIN(FECHA) FROM Clientes WHERE FECHA > ( SELECT FECHA FROM Clientes WHERE `Clientes`.`ID`='%ID%' ) ), ( SELECT FECHA FROM Clientes WHERE `Clientes`.`ID`='%ID%' ) ) AS date_diff FROM Clientes WHERE `Clientes`.`ID`='%ID%';

Re: How to calculate the interval of days between dates of the same table but of different records

Posted: 2023-08-19 15:54
by vsandoval
The code works perfectly. It was exactly what I needed

thank you for your valuable help...!!!!