title: sum function using subquery
body: <p>I have three tables:</p>
  
  <p><strong>Customer</strong></p>
  
  <pre><code>customer_id   first_name
  1              kapil
  2              rajesh
  </code></pre>
  
  <p><strong>Account</strong></p>
  
  <pre><code>Customer_id     Account_id
  1                   S1
  2                   s2
  </code></pre>
  
  <p><strong>Receipt</strong></p>
  
  <pre><code>Recipt_id   customer_id   Account_id   Transaction_type   Amount
  R1            1              s1         Deposit           40000
  R2            2              s2         Deposit             300
  R3            1              s1         withdrawal         2000
  </code></pre>
  
  <p>now i am putting query as follow </p>
  
  <pre class="lang-sql prettyprint-override"><code>select   
      c.customer_id,c.first_name,s.current_balance,s.account_id,
      (select sum(amount) 
      from receipt as r ,
          saving_account as s 
      where r.transaction_type='deposit'
          and r.account_no = s.account_id
      ) as debit,
      (select sum(amount) 
      from receipt as r ,
          saving_account as s
      where r.transaction_type='withdrawl'
          and r.account_no = s.account_id  
      )as credit 
  from customer as c 
  left outer join saving_account as s 
  inner join receipt as r on r.customer_id = s.customer_id 
  on s.customer_id = c.customer_id 
  group by c.customer_id
  </code></pre>
  
  <p>but it is giving me debit a single value for whole row and credit tooo
  i am not understanding why it is showing like that ....</p>
  
  <p>My desired result is:</p>
  
  <pre><code>customer_id customer_name account_id debit credit balance
  1           kapil         s1         40000   2000  200
  2           rajesh        s2         300     null  500
  </code></pre>