I have the following database structure:
ID | Payment (Decimal) | PaymentDate (DateTime) | PaymentStatus(int)
I am currently able to get a grouping of all of the payments over time by Year and Date and get the total across all Payment Status's using the following query;
Select
YEAR = YEAR(DueDate),
MONTH = MONTH(DueDate),
MMM = UPPER(left(DATENAME(MONTH,DueDate),3)),
Totals = sum(Payment)
from
PaymentSchedules
Where DueDate IS NOT NULL
Group by
YEAR(DueDate),
MONTH(DueDate),
DATENAME(Month,DueDate)
Order By
YEAR,
MONTH
This gives me the results so far so good.
What I would like to be able to do is have added totals for the splits in each section. So for example if each payment could be Paid (1) or Unpaid (2) or Overdue (3) I would like to not only get the number of paid / unpaid / overdue but I would also like to get the total value of unpaid items / paid items / Overdue items for each Year / Month combination.