pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Working with dates
2+ messages / 1 participants
[nested] [flat]

* Working with dates
@ 2007-07-05 19:00 Ranieri Mazili <ranieri.oliveira@terra.com.br>
  2007-07-05 20:49 ` Re: Working with dates Ranieri Mazili <ranieri.oliveira@terra.com.br>
  0 siblings, 1 reply; 2+ messages in thread

From: Ranieri Mazili @ 2007-07-05 19:00 UTC (permalink / raw)
  To: pgsql-general@postgresql.org; pgsql-sql

Hello,

I need to do the following select:

Number of days of month - weekends - holydays

So this query will return the number of days that people can work

Look that I have the holydays in one table, it's bellow:

CREATE TABLE holidays
(
  id_holidays serial NOT NULL,
  dt_holiday date,
  holiday_description character varying(60),
  input_date timestamp without time zone NOT NULL,
  CONSTRAINT holidays_pkey PRIMARY KEY (id_holidays)
)

I have no idea of how do it

If someone could help, I would appreciate.

Thanks



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Working with dates
  2007-07-05 19:00 Working with dates Ranieri Mazili <ranieri.oliveira@terra.com.br>
@ 2007-07-05 20:49 ` Ranieri Mazili <ranieri.oliveira@terra.com.br>
  0 siblings, 0 replies; 2+ messages in thread

From: Ranieri Mazili @ 2007-07-05 20:49 UTC (permalink / raw)
  To: pgsql-general@postgresql.org; pgsql-sql

-------- Original Message  --------
Subject: [GENERAL] Working with dates
From: Ranieri Mazili <ranieri.oliveira@terra.com.br>
To: pgsql-general@postgresql.org, pgsql-sql@postgresql.org
Date: 5/7/2007 16:00
> Hello,
>
> I need to do the following select:
>
> Number of days of month - weekends - holydays
>
> So this query will return the number of days that people can work
>
> Look that I have the holydays in one table, it's bellow:
>
> CREATE TABLE holidays
> (
>  id_holidays serial NOT NULL,
>  dt_holiday date,
>  holiday_description character varying(60),
>  input_date timestamp without time zone NOT NULL,
>  CONSTRAINT holidays_pkey PRIMARY KEY (id_holidays)
> )
>
> I have no idea of how do it
>
> If someone could help, I would appreciate.
>
> Thanks
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>
>
I can.

select count(A.data)
from (select (date_trunc('month',(select production_date from production 
order by production_date desc limit 1)::date)::date + x * '1 
day'::interval)::date as data from generate_series(0,31) x) A
where extract(month from A.data) = extract(month from (select 
production_date from production order by production_date desc limit 
1)::date )
and extract(dow from A.data) <> 0
and extract(dow from A.data) <> 6
and A.data not in (select dt_holiday from holidays)




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2007-07-05 20:49 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-07-05 19:00 Working with dates Ranieri Mazili <ranieri.oliveira@terra.com.br>
2007-07-05 20:49 ` Ranieri Mazili <ranieri.oliveira@terra.com.br>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox