Re: A query or maybe programmatic? - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: A query or maybe programmatic?
Date
Msg-id 20020312093922.A28330@svana.org
Whole thread Raw
In response to A query or maybe programmatic?  (S Dawalt <shane.dawalt@wright.edu>)
List pgsql-general
On Mon, Mar 11, 2002 at 11:15:29AM -0500, S Dawalt wrote:
>   I have a large pile of records in a table having, in part, the following structure:
>
> starttime timestamp
> endtime  timestamp
> portnum  integer
> serverid   integer
> <lots more garbage>
>
>   What I want is to obtain the total number of records over a period of time at each second.  So, for example, if I
havethree records as shown here: 
>
> starttime                endtime
> 3/10/2002 1:0:5      3/10/2002 1:0:10
> 3/10/2002 1:0:7      3/10/2002 1:0:11
> 3/10/2002 1:0:13    3/10/2002 1:0:14

Ok, one thing to remember about SQL is that it cannot generate new values
out of thin air, they have to come from somewhere. What you need to do is
create a table with all the timestamp values you're interested in and then:

select time, count(*)
from data
where time between data.starttime and data.endtime;

Done. HTH,
--
Martijn van Oosterhout <kleptog@svana.org>
http://svana.org/kleptog/
> If the company that invents a cure for AIDS is expected to make their
> money back in 17 years, why can't we ask the same of the company that
> markets big-titted lip-syncing chicks and goddamn cartoon mice?

pgsql-general by date:

Previous
From: Travis Bauer
Date:
Subject: Fast vector similarity metric
Next
From: "Jeff Martin"
Date:
Subject: Re: Can't get ODBC from Windows to Linux/Postgres to work