title: Query For Opening And Closing Balance In Oracle
body: <p>hi i have following table and data to get opening and closing balance of every account opening balance required gdate&lt;02-oct-2013 here is my table</p>
  
  <pre><code>create table ledger (account_no varchar2(10),gdate date,debit number(8),credit number(8))
  
  insert into ledger (account_no,gdate,debit,credit) values ('10-0001','01-oct-2013',1000,0);
  insert into ledger (account_no,gdate,debit,credit) values ('10-0001','24-oct-2013',0,440);
  insert into ledger (account_no,gdate,debit,credit) values ('20-0001','01-oct-2013',3000,0);
  insert into ledger (account_no,gdate,debit,credit) values ('30-0001','01-oct-2013',300,0);
  insert into ledger (account_no,gdate,debit,credit) values ('20-0001','16-oct-2013',1200,0);
  insert into ledger (account_no,gdate,debit,credit) values ('30-0001','17-oct-2013',0,1340);
  insert into ledger (account_no,gdate,debit,credit) values ('30-0001','24-oct-2013',500,0);
  </code></pre>
  
  <p>i need following result</p>
  
  <pre><code>ACCOUNT_NO OPENING  DEBIT  CREDIT  CLOSING
  10-0001    1000    0       440    560
  20-0001    3000    1200      0    4200
  30-0001     300    500    1340    540
  </code></pre>