title: ORACLE SQL QUERY union
body: <p>I have the following table:</p>
  
  <pre><code>site||kw||date
  M   ||50||1-1-2013
  A   ||60||1-1-2013
  ...
  </code></pre>
  
  <p>I need to show, filtering between two dates</p>
  
  <pre><code>Site||avg(kw)||MAX_KW_PERIOD||MAX_KW_TOTAL
  </code></pre>
  
  <p>being <code>MAX_KW_PERIOD</code> the maximum value of kw between the two dates and MAX_KW_TOTAL the maximum historical value of kw.</p>
  
  <p>I try with a union query:</p>
  
  <pre><code>SELECT Site,
         avg(TM.kw) "AVG_KW", 
         MAX(TM.kwGen) "MAX KW PERIOD",
         TO_NUMBER(NULL) "MAX_TOTAL"
    FROM TABLE
   WHERE DATE BETWEEN DATE1 
                  AND DATE2
  GROUP BY 
         Site
  UNION
  SELECT Site,
         TO_NUMBER(NULL)"AVG_kW",
         TO_NUMBER(NULL)"MAX KW PERIOD",
         MAX(TM.kwGEN) "MAX TOTAL" 
    FROM TABLE
  GROUP BY 
         Site
  </code></pre>
  
  <p>but i obtain:</p>
  
  <pre><code>SITE||AVG_KW||MAX_KW PERIOD||MAX TOTAL
     A||100   ||110          ||(null)
     A||(null)||(null)       ||160
  </code></pre>
  
  <p>How can i do to obtain only one row for site like</p>
  
  <pre><code>SITE||AVG_KW||MAX_KW PERIOD||MAX TOTAL
     A||100   ||110          ||160
  </code></pre>
  
  <p>thanks a lot.</p>