title: ORACLE DECODE with multiple expressions or multiple decodes
body: <p>I have the below data in an Oracle table which I'm trying to perform calculations based on TYPE &amp; QT columns.</p>
  
  <pre><code>TYPE QT STATUS  CNT
  ---- -- ------  ---
  E    A  YES     123
  E    A  NO     2540
  E    D  YES       2
  E    D  NO      787
  O    A  YES     884
  O    A  NO     6957
  O    D  YES      25
  O    D  NO     1360
  </code></pre>
  
  <p>Looks like my expected output now is different.. like below :</p>
  
  <pre><code>TYPE    TOTAL   A   A&amp;Y
  ----    -----   ----    -----
  E+O     12678   10504   1007
  E       3452     2663    123
  </code></pre>
  
  <p>My old oracle sql is below but the output is wrong when calculating the percentages:</p>
  
  <pre><code>SELECT * FROM (
      SELECT NVL(SUM(DECODE(A.QT,'A',A.CNT,'D',A.CNT)),0) AS "TOTAL",
      NVL(SUM(DECODE(A.QT,'A',A.CNT)),0) AS "A ALL",
      NVL(SUM(DECODE(A.QT,'A',ROUND(100*(NVL(A.CNT,0)/ A.CNT),2))),0) "A ALL %",
      NVL(SUM(DECODE(A.STATUS,'E',A.CNT)),0) AS "E TOTAL",
      NVL(SUM(DECODE(A.STATUS,'E',DECODE(A.QT,'A',A.CNT))),0) AS "E &amp; A TOTAL"",
      NVL(SUM(DECODE(A.STATUS,'E',ROUND(100 * SUM((DECODE(A.QT,'A',A.CNT)) / SUM(A.CNT)),3))),0) "E &amp; A %"
      FROM ALLIN A)
  </code></pre>