I need to calculate all the invoices that were paid on the first "N" days of the month. I have two tables
. INVOICE: contains account information. The only field that matters is called "datePayment"
. HOLYDAYS: This is a single column table. The entries in this table are in the form "2009-01-01", 2009-05-01 ", etc.
I should also consider Saturday and Sunday (this may not be a problem, because I could insert these days in the Hollidays table to treat them as hollidays, if necessary)
The problem is to calculate which is the "limit of payment".
select count(*) from invoice
where datePayment < PAYMENTLIMIT
My question is how to calculate this PAYMENT LINE. Where PAYMENTLIMIT is the "fifth working day of every month."
The query must be executed in Mysql and Oracle, so standard SQL must be used.
Any clues?
EDIT To match the name of the question, the pseudo-query should be read as follows:
select count(*) from invoice
where datePayment < FIRST_WORKING_DAY + N
then the question can be reduced to calculate FIRST_WORKING_DAY of each month.
Luixv source
share