title: SQL Query SELECT and Group by with conditions
body: <p>I have a table called item table.</p>
  
  <p>Sample contents:</p>
  
  <pre><code>order           product    plan qty price   term    base_price
  CO0300039921    ZZFEE0000   N   1   0.01    1       25
  CO0300039921    ZZFEE0000   N   1   0.01    1       37.13
  CO0300039921    ZZFEE0000   N   1   0.02    1       37.13
  CO0300039921    ZZFEE0000   Y   1   0       1       1
  CO0300039921    ZZFEE0000   Y   1   0       1       1
  AO1000301407    VOSVC0002W0 Y   1   0       1       3
  AO1000301407    VOACT0101   N   1   0       2       5.99
  
  
  If plan is ‘N’ Then
      get SUM(qty) AS 'quantity'
      get price AS 'rate'
  If plan is ‘Y’ Then
      get SUM(qty) AS 'quantity'
      get (term * qty) AS 'rate'
      get (base_price) AS 'base'
  
  FROM item
  WHERE order = 'CO0300039921'
  GROUP BY product, price, base_price
  </code></pre>
  
  <p>EXPECTED RESULT:</p>
  
  <pre><code> order           product    plan qty  price rate  base_price  
      CO0300039921    ZZFEE0000   N   2    0.01  0.01     -
      CO0300039921    ZZFEE0000   N   1    0.02  1        -
      CO0300039921    ZZFEE0000   Y   2    -     1        1 
  </code></pre>
  
  <p>Here is what I've tried:</p>
  
  <pre><code>SELECT CASE WHEN p8_plus_plan = 'Y' THEN 
  ( 
  
     SUM(qty_ordered),
     (p8_contract_term*qty_ordered) AS 'rate',
     product_base_price
  )
  ELSE 
  ( 
     SUM(qty_ordered),
     price AS 'rate'
  )
  END
  FROM ns_order_line 
  WHERE order_no = ? 
  GROUP BY product_id, price, p8_plus_plan, product_base_price, order_no; 
  </code></pre>
  
  <p>But I'm having an error. Please help.</p>