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 60B9852A72 for ; Fri, 6 May 2005 04:26:30 -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 58373-03 for ; Fri, 6 May 2005 07:26:26 +0000 (GMT) Received: from mail.gmx.net (pop.gmx.net [213.165.64.20]) by svr1.postgresql.org (Postfix) with SMTP id E1E0A53226 for ; Fri, 6 May 2005 04:26:25 -0300 (ADT) Received: (qmail invoked by alias); 06 May 2005 07:26:25 -0000 Received: from p5495F29D.dip.t-dialin.net (EHLO pikkewyn.bienenet) [84.149.242.157] by mail.gmx.net (mp004) with SMTP; 06 May 2005 09:26:25 +0200 X-Authenticated: #1074748 Date: Fri, 6 May 2005 09:25:35 +0200 From: Vortex To: pgsql-sql@postgresql.org Subject: select within aggregate? Message-Id: <20050506092535.060bca35.vortex25@gmx.de> Organization: private X-Mailer: Sylpheed version 1.0.3 (GTK+ 1.2.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.516 tagged_above=0 required=5 tests=FROM_ENDS_IN_NUMS X-Spam-Level: X-Archive-Number: 200505/49 X-Sequence-Number: 21362 Hi!! Of course the following is possible in various ways but i wonder if there is an elegant and simple solution: A part from apache log: remote_host varchar(50) request_uri varchar(50) ts timestamp with time zone Now i want to see which host has done how many requests. This is not difficult: SELECT remote_host, count(*) FROM apache_log GROUP BY remote_host; But now i would like to add a column to the result which shows the most recent requested uri for each group. This sounds quite easy at first glance but i see no simple solution. I suppose with max(ts) i could acquire the time of the most recent request within the group, but how do i get the corresponding request_uri without doing subquerys or something like that? Thank you very much! Klaus