From: Alvaro Herrera <alvherre@commandprompt.com>
To: James Kitambara <jameskitambara@yahoo.co.uk>
Cc: Srikanth <rssrik@yahoo.co.in>
Cc: pgsql-sql@postgresql.org
Subject: Re: SQL to Check whether "AN HOUR PERIOD" is between start and end timestamps
Date: Thu, 2 Apr 2009 09:54:04 -0400
Message-ID: <20090402135404.GD3163@alvh.no-ip.org> (raw)
In-Reply-To: <849335.93192.qm@web27903.mail.ukl.yahoo.com>
References: <19947.64230.qm@web94606.mail.in2.yahoo.com>
<49BFBC61.9020006@archonet.com>
<849335.93192.qm@web27903.mail.ukl.yahoo.com>
James Kitambara wrote:
> Dear Srikanth,
> You can solve your problem by doing this
>
> THE SQL IS AS FOLLOWS
> ASSUME TIME INTERVAL 2008-12-07 07:59:59 TO 2008-12-07 08:58:59 AND THE TABLE NAME time_interval
>
> COUNT (*) FROM
> (select customer_id, log_session_id, start_ts, end_ts , end_ts-start_ts as "Interval" from time_interval
> where end_ts-start_ts >= '1 hour'
> and '2008-12-07 07:59:59' between start_ts and end_ts)
> AS COUNT ;
Another way to phrase the WHERE clause is with the OVERLAPS operator,
something like this:
WHERE (start_ts, end_ts) OVERLAPS ('2008-12-07 07:59:59', '2008-12-07 08:59:59')
What I'm not so sure about is how optimizable this construct is.
--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: alvherre@commandprompt.com, jameskitambara@yahoo.co.uk, rssrik@yahoo.co.in
Subject: Re: SQL to Check whether "AN HOUR PERIOD" is between start and end timestamps
In-Reply-To: <20090402135404.GD3163@alvh.no-ip.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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