日期:2014-05-17  浏览次数:20739 次

如何得到余额?如何得到余额?如何得到余额?
如何得到余额?
会计凭证表(KJ)
   id   jfmoney(借方金额)  dfmoney(贷方金额)
    1         100              200
   2         120              120
   3         150              150
   ...      ....              ...
如何得到余额
余额=上一行的余额-货方+借方。借就加,货就减。贷和借不会出现在同一行。


------解决方案--------------------
引用:
如何得到余额?
会计凭证表(KJ)
   id   jfmoney(借方金额)  dfmoney(贷方金额)
    1         100              200
   2         120              120
   3         150              150
   ...      ....              ...
如何得到余额
余额=上一行的余额-货方+借方。借就加,货就减。贷和借不会出现在同一行。


需要怎样的结果,能贴处理吗
------解决方案--------------------
引用:
写错了,不好意思


应该是怎样的,能不能把你想要的结果,重新贴出来
------解决方案--------------------
对了 你上面的3         150             0         -20-0+150=120 ,余额应该是130吧,
是这样吗:



drop table tb


create table tb(id int,jfmoney int,dfmoney int)


insert into tb
select 1  ,100   , 0        
union all select  2 , 0 , 120       
union all select  3 ,150 ,0        
union all select  4 ,  0,300       


;with t
as