On 2009-03-17, Srikanth <rssrik(at)yahoo(dot)co(dot)in> wrote:
> Dear all,
>
> I have a table that records User Login Sessions with two timestamp fields. =
> Basically Start of Session and End of a Session (start_ts and end_ts). Each=
> row in the table identifies a session which a customer has used.=A0=20
>
>
> I have to find out how many User Sessions that were present in any given "1=
> HOUR TIME PERIOD".=A0 A single User Session can span across many days.
select count(*) from session
WHERE start_ts < TIME + '1 hour'::interval
AND end_ts >= TIME;
(replace both ocurrences of TIME with the time the interval starts)