title: Retrieve data from database dynamically
body: <p>I have done some calculation using the data from <code>chartofaccount</code> table I have subtracted <code>SUM(debit_amount)-SUM(credit_amount)</code> when <code>coa_type="ACCOUNT_RECEIVABLE"</code> and <code>SUM(credit_amount)-SUM(debit_amount)</code> when <code>coa_type='SECURITY_DEPOSIT'</code> for one <code>customerID</code> but now I want that all the values will appear in one row for all<code>coa_type</code> what should I do?I had group by <code>coa_type</code> because calculation of <code>debit_amount</code> and <code>credit_amount</code> is different for different <code>coa_type</code>.Please let me know If I am not clear.</p>
  
  <p>here is my query  .. </p>
  
  <pre><code>SELECT  
      CASE WHEN coam.`coa_type`='ACCOUNTS_RECEIVABLE'
  THEN SUM(`debit_amount`)-SUM(`credit_amount`)
  END AS receivable,
  
  CASE WHEN coam.`coa_type`='SECURITY_DEPOSIT'
  THEN SUM(`credit_amount`)-SUM(`debit_amount`)
  END AS securitydeposit
  
  ,`customer_master`.`customer_credit_limit`
  ,coam.`coa_type`  ,`customer_priority`.`name`
  
   FROM `journal_details`  
  
  INNER JOIN `journal`  ON `journal`.`id`=`journal_details`.`journal_id`
  INNER JOIN `customer_master`  ON      `customer_master`.`code`=`journal_details`.`prefix_code`
   INNER JOIN `customer_priority` ON `customer_priority`.`id` = `customer_master`.`customer_priority_id`
  INNER JOIN `chart_of_accounts`  ON `chart_of_accounts`.`id`= `journal_details`.`chart_of_accounts_id`
   INNER JOIN `chart_of_accounts_mapping` coam ON coam.`chart_of_accounts_id`= `chart_of_accounts`.`id`
  
   WHERE `customer_master`.`code` =(SELECT CODE FROM `customer_master`  WHERE `customer_master`.id=11) 
   GROUP BY coam.`coa_type` 
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/8OCJA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8OCJA.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/3cJSU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3cJSU.png" alt="enter image description here"></a></p>