Hello friends,
I am new to this site, this is my first post, My question is..
How to calculate the one rows value for next row value?
select @rownum:=@rownum+1 "sl.no",
b.bus_activity_desc "Type",r.trn_no,
o.Office_name,o.Address,o.Address2,o.Address3,
DATE_FORMAT(r.trn_date,GET_FORMAT(DATE,'EUR')) as trn_date,
l.Account_id ,
if(r.trn_type=6,r.total_trn_value,0) "Credit",
if(r.trn_type=7,r.total_trn_value,0) "Debit",
if(r.trn_type=6 ,@cbal:=(r.total_trn_value+@cbal),@cbal:=(@cbal-r.total_trn_value)) "Closing Balance"
from(select @rownum:=0) s,
office_master o,
center_group_customer_master ce,
receipt_payment_header r,
saving_accounts l,
(select @cbal:=0) c ,
accounts_summary_details a,
business_activity_master b
where a.Account_id=l.savings_id and
a.Customer_id=l.Customer_id and
a.Product_id=2 and
r.Trn_type in (6,7) and
r.Customer_id=l.Customer_id and
r.Account_id=l.savings_id and
b.Bus_activity_code=r.Trn_type and
l.account_id='23' and
r.trn_date between '2006-06-01' and '2008-06-31' and
o.Office_id=ce.office_id and
ce.customer_id=r.customer_id order by r.trn_no;
The above given is my query, don't search any mistakes in that, I am just asking the logic to calculate "closing balance" according to r.trn_no, please help me