I count the number of working days using a query in SQL:

SELECT day :: DATE, extract('dow' FROM day) BETWEEN 1 AND 5 AS working_day FROM generate_series('2015-01-01', (date_trunc('day', pday() + INTERVAL '1 month') :: DATE - 1) , INTERVAL '1 day') AS day 

Query result: enter image description here

How can I take holidays into this request? I have a separate Holidays table that looks like this: country, date, type. And I need to consider only for certain countries of the Federal Holidays (This is indicated in the type column).

  • Add the Holidays table to the query as another data source with the required selection (by country) and take into account the related (LEFT JOIN, by the way) data from it when calculating the field working_day - Akina
  • What field is the join? - user249955
  • By date, the stump is clear, plus pre-selection by type and, if necessary, then by country. - Akina

0