Re: [SQL] Counting days ...

2008-03-14 Thread Aarni Ruuhimäki
On Friday 14 March 2008 18:09, Frank Bax wrote: > > > > Is zero days/nights, ignored. Not even possible to insert in the > > application. end_day must be greater than start_day. > > You should still consider rows that are "out of range" or "zero nights" > in your test cases to make sure your report

[SQL] DB Design

2008-03-14 Thread PostgreSQL Admin
I have a inventory system design in which I would like some help with to see if it's efficient. The products are broken into: Product tables Property tables Configurable Products - this would include colors (i.e. - black, blue and green) tied to products I'm thinking of breaking inventory in

Re: [SQL] Counting days ...

2008-03-14 Thread Frank Bax
Aarni Ruuhimäki wrote: Thanks Frank, astart_day before period_start, end_day before period_start This I don't have to care about as it is not in the period we are looking at. bstart_day = period_start, end_day = period_start Is zero days/nights, ignored. Not even possible to inser

Re: [SQL] Counting days ...

2008-03-14 Thread Steve Crawford
Aarni Ruuhimäki wrote: Thanks Steve, I'm not sure if I quite grasped this. It gives a bit funny results: SELECT sum ((date_smaller(res_end_day, '2007-12-31'::date) - date_larger(res_start_day, '2006-12-31'::date)) * group_size) AS days_in_period, c.country_name AS country FROM product_res p

Re: [SQL] Counting days ...

2008-03-14 Thread Aarni Ruuhimäki
Thanks Frank, Top and between posting ... On Friday 14 March 2008 15:58, Frank Bax wrote: > Frank Bax wrote: > > Aarni Ruuhimäki wrote: > >> Anyway, I have to rethink and elaborate the query. I know that it will > >> usually be on a monthly or yearly basis, but a reservation can > >> actually be

Re: [SQL] Counting days ...

2008-03-14 Thread Frank Bax
Frank Bax wrote: Aarni Ruuhimäki wrote: Anyway, I have to rethink and elaborate the query. I know that it will usually be on a monthly or yearly basis, but a reservation can actually be any of the following in relation to the given (arbitrary) period: 1. start_day before period_start, end_da

Re: [SQL] Counting days ...

2008-03-14 Thread Frank Bax
Aarni Ruuhimäki wrote: Check my work, but I think the sum part of the query simply becomes: sum ( ( date_smaller(res_end_day, '2008-02-29'::date) - date_larger(res_start_day, '2008-01-31'::date) ) * group_size ) Basically remove the "+1" so we don't include both start and end dates but

Re: [SQL] Counting days ...

2008-03-14 Thread Aarni Ruuhimäki
> > Check my work, but I think the sum part of the query simply becomes: > > sum ( > ( > date_smaller(res_end_day, '2008-02-29'::date) - > date_larger(res_start_day, '2008-01-31'::date) > ) * group_size > ) > > Basically remove the "+1" so we don't include both start and end dates > but mov