title: sum if values oracle sql
body: <p>I have got a query like</p>
  
  <pre><code> select distinct i.charge_type, cp.name, sum(i.amount)
   from charge.gp_schedule gp, charge.gsm_charge_plan i, charge cp
   where i.code = gp.sales_audit_code
   and cp.code = gp.code
   group by i.charge_type ,cp.name
  </code></pre>
  
  <p>which outputs for example the following</p>
  
  <pre><code>     GSMFixedCharge         FCFBBR15           15
       **GSMUsageCharge**    Call Charges       2.16
       **GSMUsageCharge**   Service Charges      2
       GSMFixedCharge         Line Rental       23.98
       GSMFixedCharge         FCFAFPBL            1
  </code></pre>
  
  <p>How can I further sum the values only based on 'GSMUsageCharge' in the same query so the desired output would be</p>
  
  <pre><code>     GSMFixedCharge  FCFBBR15          15
       GSMUsageCharge  Call Charges      4.16
       GSMFixedCharge  Line Rental      23.98
       GSMFixedCharge  FCFAFPBL           1
  </code></pre>
  
  <p>I have tried something like</p>
  
  <pre><code>  select distinct i.charge_type, cp.name, DECODE(i.charge_type, 'GSMUsageCharge', sum (i.amount)    
     group by i.charge_type) result
  </code></pre>
  
  <p>but it does not work...</p>