title: Calculation of balance after each transaction
body: <p>I have table like this:</p>
  
  <pre><code>cust_id acc_no trans_id  trans_type amount
  1111    1001    10   credit     2000.0  
  1111    1001    11   credit     1000.0
  1111    1001    12   debit      1000.0  
  2222    1002    13   credit     2000.0  
  2222    1002    14   debit      1000.0
  </code></pre>
  
  <p>I want a Hive query or sql query for every transaction done by a customer the balance should be calculated so.</p>
  
  <p>I want output as follows:</p>
  
  <pre><code>cust_id acc_no trans_id  trans_type amount      balance
  1111.0  1001.0  10.0     credit    2000.0   2000.0
  1111.0  1001.0  11.0     credit    1000.0   3000.0
  1111.0  1001.0  12.0     debit     1000.0   2000.0
  2222.0  1002.0  13.0     credit    2000.0   2000.0
  2222.0  1002.0  14.0     debit     1000.0   1000.0
  </code></pre>
  
  <p>I've tried</p>
  
  <pre><code>SELECT * 
  FROM   (SELECT cust_id, 
                 acc_no, 
                 trans_id, 
                 trans_type, 
                 amount, 
                 CASE 
                   WHEN Trim(trans_type) = 'credit' THEN ball = 
                   Trim(bal) + Trim(amt) 
                   ELSE ball = Trim(bal) - Trim(amt) 
                 end 
          FROM   ban) l; 
  </code></pre>