I have a database where records are not kept every day, though I need to calculate balance changes between dates where There are records (except dates where there are no entries).
For example, I want to see such a result:
trade_date balance prev_date prev_balance diff 2014-01-16 -2648 2014-01-13 436 -3084 2014-02 -04 37 2014-01-16 -2648 2685 2014-02-11 37 2014-02-04 37 2014-02-12 37 2014-02-11 37 2014-02-21 -9633 2014-02-12 37 -9670 2014-03-03 396 2014-02-21-9633 10029 2014-04-02 -10252 2014 -03-03 396 -10648 2014-04-03 -7033 2014-04-02 -10252 3219 2014-05- 21 -6849 2014-04-03 -7033 184 Unfortunately I do not know the interval between the present and the previous dates because it is always different so I can not do anything like this. Like DATE_SUB This is what I have done:
from select * (select business_date, balance by table 1 order by business_date) d LEFT JOIN (choose business_date as prev_date, trade_data Balance as the balance before order of Table 2) a.prev_date & gt; D.business_date
but it only returns a bunch of tap for the previous column.
All the things I have read on this topic include making dates for the table, but this will not work for me because my date list is incomplete, I only want to include dates whose We have records for
Any suggestion about accessing this will be very much in your first derived table 'D', generate a line number and include in:
To do this I have written this.
No comments:
Post a Comment