title: How to check two conditions in mysql sum
body: <pre><code>select cust_code,occu_name
  , SUM(CASE WHEN VoucherType = 'S' THEN Amount ELSE 0 END) AS salesSum
  ,SUM(CASE WHEN VoucherType = 'I' THEN Amount ELSE 0 END) AS interestSum
  ,SUM(CASE WHEN VoucherType = '' THEN Amount ELSE 0 END) AS interest_sum
  ,SUM(CASE WHEN VoucherType = 'P' THEN Amount ELSE 0 END) AS chequereturn_sum
  ,SUM(CASE WHEN VoucherType = 'R' THEN Amount ELSE 0 END) AS receipt_sum
  ,SUM(CASE WHEN VoucherType = 'R' THEN Amount ELSE 0 END) AS receipt_sum
  ,SUM(CASE WHEN VoucherType = 'N' THEN Amount ELSE 0 END) AS credit_sum
  ,SUM(CASE WHEN (DrCrType = 'DR' and VoucherDate &lt;= '2012-04-01') THEN Amount ELSE (Amount*-1)) AS opening_sum
  from bmwregistration, ledger_transactions
  where bmwregistration.ledger_id = ledger_transactions.OccupierID and
    VoucherDate &gt;= '2012-04-01' and
    VoucherDate &lt;= '2013-02-01'
  group by cust_code
  </code></pre>
  
  <p>How to check two conditions in sum function <code>SUM(CASE WHEN (DrCrType = 'DR' and VoucherDate &lt;= '2012-04-01') THEN Amount ELSE (Amount*-1)) AS opening_sum</code></p>