Select
, UnpaidInvoices.* FROM (
Select
-- get the first unpaid invoices only => min DueDate
Row_Number() Over (Partition By Invoice.ContractId Order By Invoice."DueDate" ASC ) FIRST_INVOICE
, To_Char(Cast(Invoice.Amount As Number(15,0)), '999G9999G999G999G999D99') As "InvoiceAmount"
-- ; Select Count(*)
From Invoice
Inner Join Contract
On ( Invoice.ContractId = Contract.ContractId )
Where 1=1
AND Invoice.IsPaid = 0
-- filter by dates ...
And Invoice.DueDate > Sysdate - 30
And Invoice.DueDate < Sysdate -17
) UnpaidInvoices
Where 1=1
AND FIRST_INVOICE = 1
No comments:
Post a Comment
- the first minus - Comments have to be moderated because of the spammers
- the second minus - I am very lazy at moderating comments ... hardly find time ...
- the third minus - Short links are no good for security ...
- The REAL PLUS : Any critic and positive feedback is better than none, so your comments will be published sooner or later !!!!