Note that there are some explanatory texts on larger screens.

plurals
  1. POpopulating missing dates and max date
    primarykey
    data
    text
    <p>I have following data from banking system: <code>date, product code, due date.</code> </p> <p>What I need to do is to populate for each product <code>due_dates</code> backwards i.e. for previous months but only on condition that <code>due_date &lt;= date.</code> </p> <p>I would also like to populate max_date that is date for the most recent due_date within each product.</p> <p>As you can see, I may have many due_dates within one product or none. </p> <p>If there is more than one date, previous shouldn't be overwritten.</p> <p>This is what it looks like now:</p> <pre><code> date product due_date ------------------------------------------ 2012-01-31 a1 2012-02-28 a1 2012-01-31 b1 2012-02-28 b1 2012-03-31 b1 2012-04-30 b1 2012-02-18 2012-05-31 b1 2012-06-30 b1 2012-05-31 2012-07-31 b1 2012-08-31 b1 2012-09-30 b1 2012-09-01 2012-10-31 b1 2012-04-30 c1 2012-05-31 c1 2012-06-30 c1 2011-03-01 2012-07-31 c1 </code></pre> <p>and this is the result I would like to get:</p> <pre><code> date product due_date max_date -------------------------------------------------------- 2012-01-31 a1 2012-02-28 a1 2012-01-31 b1 2012-09-30 2012-02-28 b1 2012-02-18 2012-09-30 2012-03-31 b1 2012-02-18 2012-09-30 2012-04-30 b1 2012-02-18 2012-09-30 2012-05-31 b1 2012-05-31 2012-09-30 2012-06-30 b1 2012-05-31 2012-09-30 2012-07-31 b1 2012-09-30 2012-08-31 b1 2012-09-30 2012-09-30 b1 2012-09-01 2012-09-30 2012-10-31 b1 2012-09-30 2012-04-30 c1 2011-03-01 2012-06-30 2012-05-31 c1 2011-03-01 2012-06-30 2012-06-30 c1 2011-03-01 2012-06-30 2012-07-31 c1 2012-06-30 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload