title: Join Two table with Date range and grouped data
body: <p>I want the data from two tables in single table by filtering out based on the date and then group data by two columns.
  For Example:- User will give account_id,start_date and end_date by which I will filter the data from both the tables.</p>
  
  <p>This Is Inward Table</p>
  
  <hr>
  
  <blockquote>
  <pre><code>ID    Account_Id  Brand   Quality Sheets  Weight  Inward_Date
   1        1           B1    Q1      10    10       01-05-2019
   2        1           B1    Q2       5     5       02-05-2019
   3        2           B1    Q1       9     9       03-05-2019
   4        1           B1    Q1       7     7       04-05-2019
   5        1           B2    Q1       2     2       05-05-2019
   6        2           B2    Q2       8     8       06-05-2019
   7        1           B1    Q2       4     4       07-05-2019
   8        1           B1    Q1       4     4       08-05-2019
  </code></pre>
  </blockquote>
  
  <p>This is Outward Table</p>
  
  <hr>
  
  <blockquote>
  <pre><code>ID    Account_Id  Brand   Quality Sheets  Outward_date
   1       1            B1       Q1     5   02-05-2019
   2       1            B1       Q1     2   03-05-2019
   3       2            B1       Q1     1   03-05-2019
   4       1            B1       Q1     2   04-05-2019
   5       1            B1       Q1     2   05-05-2019
  </code></pre>
  </blockquote>
  
  <p>Now The I need a query which will filter the data based on Date and Account_ID and combine Brand and Quality column and add the Sheets like given below</p>
  
  <p>Final OutPut</p>
  
  <hr>
  
  <blockquote>
  <pre><code>Accnt_ID Brand Quality    Opening_Sheets Total_In Total_Out
  1        B1      Q1             10         7         9
  1        B1      Q2              0         9       NULL
  1        B2      Q1              0         2       NULL
  </code></pre>
  </blockquote>
  
  <p>Explanation of output table:- I want to club the data of Inward and Outward table by grouping Brand and Quality together Summing the Sheets which are Inward and Outward in that particular period.For the sheets which are inward but not outward then in Total_Out column it will NULL.
  For Opening_sheets column - It represents the sheets which are available in the system before start_date. I guess it should be like fetching all the inward sheets before that start_date and subtract it will total out sheets.</p>