在 SQL Server 中计算债务期限

发布于 2024-09-24 00:34:16 字数 339 浏览 5 评论 0原文

我有三个表:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

友谊不毕业 2024-10-01 00:34:16

刚才一直在玩纸笔。这是否像这样简单:

Amnt Current Debt at Time = Sum(Debits to Time) - Sum (All Credits)

那么在 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:

Amnt Current Debt at Time = Sum(Debits to Time) - Sum (All Credits)

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文