Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Sql > Counting days ....
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 13 Topic 3348 of 3799
Post > Topic >>

Counting days ...

by aarni@[EMAIL PROTECTED] (Aarni =?iso-8859-1?q?Ruuhim=E4ki?=) Mar 13, 2008 at 08:25 PM

Hi all,

A bit stuck here with something I know I can do with output / loops /=20
filtering in the (web)application but want to do in SQL or within
PostgreSQ=
L.

Simply said, count days of accommodation for a given time period.

E.g.

res_id 1, start_day 2008-01-25, end_day 2008-02-15, number of persons 6
res_id 2, start_day 2008-02-10, end_day 2008-02-15, number of persons 4

for the period from 2008-02-01 to 2008-02-29 these two rows would give a
to=
tal=20
of

15 days x 6 persons + 4 days x 5 persons =3D 110 days

SELECT SUM(
CASE
WHEN res_start_day >=3D '2008-01-01' THEN
(res_end_day - res_start_day)
ELSE (res_end_day - (DATE '2008-01-01' - INTEGER '1'))
END
* group_size) AS days_in_period
FROM product_res pr
WHERE res_end_day >=3D '2008-01-01' AND res_end_day <=3D '2008-12-31';

 days_in_period
----------------
           68383
(1 row)

Ok, but a reservation can be of any nationality / country:

SELECT count(country_id) FROM countries;
 count
-------
   243
(1 row)

Country_id is also stored in the product_res table.

I would like to, or need to, get the total split into different
nationaliti=
es,=20
like:

FI 12345
RU 9876
DE 4321
....

Anyone ?

With very best regards,

--=20
Aarni Ruuhim=E4ki
---
Burglars usually come in through your windows.
---

--=20
Sent via pgsql-sql mailing list (pgsql-sql@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
 




 13 Posts in Topic:
Counting days ...
aarni@[EMAIL PROTECTED]   2008-03-13 20:25:27 
Re: Counting days ...
scrawford@[EMAIL PROTECTE  2008-03-13 11:58:46 
Re: Counting days ...
aarni@[EMAIL PROTECTED]   2008-03-13 22:09:33 
Re: Counting days ...
scrawford@[EMAIL PROTECTE  2008-03-13 13:22:41 
Re: Counting days ...
aarni@[EMAIL PROTECTED]   2008-03-14 15:04:54 
Re: Counting days ...
fbax@[EMAIL PROTECTED] (  2008-03-14 09:43:36 
Re: Counting days ...
fbax@[EMAIL PROTECTED] (  2008-03-14 09:58:34 
Re: Counting days ...
aarni@[EMAIL PROTECTED]   2008-03-14 17:13:40 
Re: Counting days ...
fbax@[EMAIL PROTECTED] (  2008-03-14 12:09:20 
Re: Counting days ...
aarni@[EMAIL PROTECTED]   2008-03-14 19:25:26 
Re: Counting days ...
fbax@[EMAIL PROTECTED] (  2008-03-15 12:05:17 
Re: Counting days ...
aarni@[EMAIL PROTECTED]   2008-03-15 19:06:43 
Re: Counting days ...
scrawford@[EMAIL PROTECTE  2008-03-14 08:59:49 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Dec 1 22:16:26 CST 2008.