在 SQL Server 中计算债务期限
我有三个表:
Charges
Payments
Adjustments
每个表都有一个值,称为“金额”。没有对该数据进行分配,我们假设最旧的付款正在支付最旧的费用或调整。每个金额可以是 +ve 或 -ve。
我需要根据当前债务余额生成一份显示债务期限的报告,其中余额是所有表中每个金额的总和。但是,债务年龄必须是当前债务年龄。如果一个账户在 10 月份借记,但在 11 月份清零,然后在 2 月份借记,则债务年龄将为 2 月。需要提供每个未清余额账户的 30、60、90 天明细。
抱歉,如果这还不清楚,但如果您之前已经这样做过,您就会明白我的意思。有什么指点吗?
I have three tables:
Charges
Payments
Adjustments
Each has a value, called Amount. There are no allocations done on this data, we are assuming the oldest Payments are paying the oldest Charges or Adjustments. Each Amount could be +ve or -ve.
I need to produce a report which shows the age of the debt, based on the current balance being in debt, where the balance is the sum of each Amount in all tables. However, the age of the debt must be the Age of the current debt. If an account was in debit in October, but was zeroed in November and then in Debit in February, the Age of the Debt would be February. In need to provide a 30, 60, 90 day breakdown of each account whose balance is outstanding.
Sorry if this isn't clear, but if you've done it before you'll know what I mean. Any pointers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
刚才一直在玩纸笔。这是否像这样简单:
那么在 SQL 中:
将所有 +ve 费用、-ve 调整或 -ve 付款转换为借方(UNION)
将所有 -ve 费用、+ve 调整或 +ve 付款转换为积分 (UNION)
对于您的每个年龄点,计算该点的借方总和并减去所有时间的所有贷方。 (SUM 和 GROUP BY)
这有什么问题吗?
Just been playing with a pen and paper. Is this as simple as:
So in SQL:
Convert All +ve Charges, -ve Adjustments or -ve Payments to Debits (UNION)
Convert all -ve Charges, +ve Adjustments or +ve Payments to Credits (UNION)
For each of your age points, get the Sum of Debits to that point and subtract all of the credits for all time. (SUM and GROUP BY)
Any problems with this?