求SQL语句 急!!!!!!!!!!!

xpfoo2010 2011-03-23 12:49:11
有这样一个业务背景:
业务员做收款计划单 单据上体现出来以下信息保存在table:t_plan(表头) t_planentry(表体)里面:
表头
单据号:id
客户号:fcust_id
总金额:famount
还款保证金:fkepamount
月利息:ffax
表体:
单据号:id
分录号:fentry
应还时间:fdate
应还金额:fpay

因为分期还款不但要每期气应还的款项,还要还每期的利息:每期还的利息=(累计剩余应还款金额-还款保证金)*月利息,所以要体现出来每期的要还的利息额,必须要在一张表里面体现出来累计剩余应还款金额.
举一个例子:业务员录入一张单据如下:
收款计划单
单据号:num001 客户号: 001 总金额:1000 还款保证金:20 月利率:0.08%


分录号 应还时间 应还金额
1 2011-01-01 500
2 2011-02-01 300
3 2011-03-01 100
4 2011-04-01 100


也就是说,应收客户1000元 ,分四期收完,每期除了还应还的金额外,还要还利息,利息计算如上.那么这个时候需要一张计算累计剩余应还款金额的表体现出来,也就是根据以上信息,得到如下字段的表:'
累计剩余应还款金额 分录号 应还时间 应还金额
1000 1 2011-01-01 500
500 2 2011-02-01 300
200 3 2011-03-01 100
100 4 2011-04-01 100
求指教
...全文
190 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
birdmonster 2011-03-24
  • 打赏
  • 举报
回复

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
rjthinking 2011-03-24
  • 打赏
  • 举报
回复

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
X_0 2011-03-23
  • 打赏
  • 举报
回复
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
sleet96 2011-03-23
  • 打赏
  • 举报
回复
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

是不是要这个结果?
--小F-- 2011-03-23
  • 打赏
  • 举报
回复
没看懂。
dawugui 2011-03-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 dearbinge 的回复:]
题目太长 建议短小一点
[/Quote]同意
dearbinge 2011-03-23
  • 打赏
  • 举报
回复
题目太长 建议短小一点

27,581

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧