Subject | Re: [firebird-support] How to add previous column value to current value? |
---|---|
Author | setysvar |
Post date | 2016-03-29T17:20:14Z |
>I need something like thisI agree with Thomas in that EXECUTE BLOCK is probably the best solution,
>
>Name Date Days betwen Previous date
>----------------------------------------------------------------------
>Name1 date1 0
>Name2 date2 date2-date1
>Name3 date3 date3-date2
but an (inferior) alternative is:
SELECT T1.Name, T1.MyDate, coalesce(T1.MyDate - (SELECT MAX(T2.MyDate)
FROM MyTable T2 WHERE T1.MyDate > T2.MyDate), 0)
FROM MyTable T1
The main reason for me calling it inferior, is that it will be slow for
large tables without additional selective WHERE criteria for T2.
HTH,
Set