X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 56DC85280B for ; Mon, 4 Jul 2005 08:58:20 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 97745-04 for ; Mon, 4 Jul 2005 11:58:11 +0000 (GMT) Received: from ibox-server.openwired.net (60.Red-81-44-253.pooles.rima-tde.net [81.44.253.60]) by svr1.postgresql.org (Postfix) with ESMTP id D6D125284E for ; Mon, 4 Jul 2005 08:58:09 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by ibox-server.openwired.net (Postfix) with ESMTP id EB33A2E00F8 for ; Mon, 4 Jul 2005 13:55:24 +0100 (BST) Received: from ibox-server.openwired.net ([127.0.0.1]) by localhost (ibox-server.openwired.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 08527-05 for ; Mon, 4 Jul 2005 13:55:23 +0100 (BST) Received: from 10.0.0.21 (unknown [10.0.0.21]) by ibox-server.openwired.net (Postfix) with ESMTP id E86CC2E00F6 for ; Mon, 4 Jul 2005 13:55:22 +0100 (BST) Subject: select values from interval From: Josep =?ISO-8859-1?Q?Sanmart=ED?= To: pgsql-sql@postgresql.org Content-Type: text/plain Organization: OpenWired Date: Mon, 04 Jul 2005 14:00:57 +0200 Message-Id: <1120478457.3506.17.camel@josep> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 (2.0.2-3) Content-Transfer-Encoding: 7bit X-Virus-Scanned: by I-Box de Openwired (www.openwired.com) Antivirus-Antispam at openwired.net X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.05 tagged_above=0 required=5 tests=FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200507/12 X-Sequence-Number: 21990 Hi, I've this table: am_conn(mac, user_ip, start_time, end_time). Each time a user connects with a remote server a new row is added, when the user is disconnected the end_time field is set. Now, I want to know if there is a way (sql statement) to know how many connections are up during an interval time, for example 60 segs, and to repeat this interval from a beginning date to end date. I think it should be something like: SELECT COUNT(*) FROM am_conn WHERE start_time between '2004-01-01 10:28:00.000' AND end time '2005-01-01 10:28:00.000' GROUP BY .....something..... I made some tests but I can't obtain the correct statement. Maybe, probably, it should be done without group by. Thanks.