------解决方案-------------------- select d.id,d.fentry,d.fdate,d.fpay,h.famount-sum(isnull(d1.fpay,0)) as famount_Remain,d.fpay+(h.famount-sum(isnull(d1.fpay,0)))*h.ffax as fpay_Actual from t_planentry d left join t_planentry d1 on d.id=d1.id and d.fdate>d1.fdate left join t_plan h on d.id=h.id group by d.id,d.fentry,d.fdate,d.fpay,h.famount,h.ffax
是不是要这个结果?
------解决方案-------------------- select Totalfpay=sum(t2.fpay),t1.fentry,t1.fdate,t1.fpay from t_planentry t1, t_planentry t2 where t1.id=t2.id and t1.fdate>=t2.fdate and t1.id=@id group by t1.fentry,t1.fdate,t1.fpay
------解决方案--------------------
SQL code
select p1.fentry,p1.fdate,p1.fpay,sum(p2.fpay) famount
from t_planentry p1 inner join
(select fentry,fpay from t_planentry ) p2
on p1.fentry<=p2.fentry
group by p1.fentry,p1.fdate,p1.fpay
------解决方案--------------------
SQL code
create table tb_temp
(
id int,
date datetime,
mone int
)
insert into tb_temp
select 1,'2011-01-01',500 union all
select 2,'2011-02-01',300 union all
select 3,'2011-03-01',100 union all
select 4,'2011-04-01',100
select
calculate=(select sum (mone) from tb_temp b where b.id >= a.id)
,* from tb_temp a