Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f5DLIdE17148 for ; Wed, 13 Jun 2001 17:18:39 -0400 (EDT) (envelope-from josh@agliodbs.com) Received: from [209.10.40.250] (account ) by davinci.ethosmedia.com (CommuniGate Pro WebUser 3.4.1) with HTTP id 71610; Wed, 13 Jun 2001 14:18:31 -0700 From: "Josh Berkus" Subject: Re: Determine the time difference from records in a select To: "Creager, Robert S" , "'SQL - PGSQL'" X-Mailer: CommuniGate Pro Web Mailer v.3.4.1 Date: Wed, 13 Jun 2001 14:18:31 -0700 Message-ID: In-Reply-To: <10FE17AD5F7ED31188CE002048406DE8514DE0@lsv-msg06.stortek.com> MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Archive-Number: 200106/203 X-Sequence-Number: 3461 Robert: > I have a firewall hit database which keeps the date of the hit and > the > offenders IP (among other items). I would like to be able to execute > a > select which would show each unique IP and the time difference from > the > latest hit to the first hit. I can do this in scripts, but was > wondering if > there is a pure SQL query/queries way to accomplish this. You need to use a subselect, which means you need to be running 7.1 or better. Here's the basic idea: SELECT agg_last.ip_address, first_hit, last_hit, (last_hit - first_hit) AS hit_interval FROM (SELECT ip_address, min(hit_date) as first_hit ______AGLIO DATABASE SOLUTIONS___________________________ Josh Berkus Complete information technology josh@agliodbs.com and data management solutions (415) 565-7293 for law firms, small businesses fax 621-2533 and non-profit organizations. San Francisco