title: how to use windows function during merge in sql
body: <p>I am working in oracle sql. I have two table which is linked to each other by one column - <code>company_id</code> (see on the picture); I want to merge <code>table 1</code> to <code>table 2</code> and calculate 6 month average (6 month before <code>period</code> from table 2) of income for each <code>company_id</code> and each date of <code>table2</code>. I appreciate any code/idea how to solve this task.</p>
  <img src="https://i.stack.imgur.com/Tm5Og.png">