您的位置:首页 > 数据库

利差的计算

2004-07-01 16:23 561 查看
在一般的数据库设计中,一般无法保留客户每天的资金情况,一般只保留资金增量表,但因为利息积数是每天变化,故保留的利息积数也是资金变化当日的利息积数,计算利差可不能简单的采用增量表中的利息积数。
开始考虑,对每天的利差:
round(a.balance * 企业利率/360,2) - round(a.balance * 个人利率/360,2)
但个人利率实际是不相同的,故很多时候不能直接使用个人利率,而直接采用利息计算
round((a.interest_acc - coalesce(b.interest_acc,0.00)) * 企业利率/360,2)
   - (a.pending_interest - coalesce(b.pending_interest,0.00))
a为当天余额表,b为前一交易日余额表
可是上面的算法还是有问题,如果存在结息就麻烦了
case when a.interest_acc<=b.interest_acc then round(a.interest_acc*企业利率/360,2)-a.pending_interest
else round((a.interest_acc - coalesce(b.interest_acc,0.00)) * 企业利率/360,2)
   - (a.pending_interest - coalesce(b.pending_interest,0.00))
这个只对全部结息有效,对部分结息又没办法了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  360 数据库 算法