Script For A Receivable Aging Report From An MS SQL Database Table

  Kiến thức lập trình

I want to make a receivable aging report for a customer using MS SQL Server Database.
I am using MS SQLSERVER 2017.

Below the image of the ledger table is shown.
Ledger Table

As can be seen the sales # 10/9/8/7 are fully included in the total balance while the sales # 6 is partially included. The amount still due for payment from the sale # 6 is 345.
Now I want my aging report to look like this as on 25th April 2024
Required Aging Report

What script should I write to get this report in output?

I tried some scripts but could not get the required output. So I need the solution from scratch.

LEAVE A COMMENT