title: Temporary tables
body: <p>I have two temp tables t1 and t2,
  t1 containing:</p>
  
  <pre><code>Product    Sum(products)  StartDate
  d1          10         06/03/2016
  d2          20         13/03/2016 
  d3          30         20/03/2016
  </code></pre>
  
  <p>based on the startdate</p>
  
  <p>and t2 contaning:</p>
  
  <pre><code>subproducts   sum(subproduct) startdate
  d1.a1           10            06/03/2016
  d2.a2           20            13/03/2016
  d3.a3           30            20/03/2016 
  </code></pre>
  
  <p>t3 containing</p>
  
  <pre><code>product subproduct
  d1        a1
  d2        a2
  d3        a3
  </code></pre>
  
  <p><br /></p>
  
  <pre><code>create table t2 as(select t3.subproduct,t1.startdate,sum(subproduct) over(partition by t1.product) from t3,t1
  where t3.product =t1.product
  grouping by startdate
  </code></pre>
  
  <p>I need to first check if <code>sum(subproduct)</code> is zero, if not then calculate the <code>sum(product)/sum(subproduct)</code>, and then take the average of this value over 10 weeks assuming I have ten weeks data. Can this be done inside the temp table <code>t2</code> and how?</p>