pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Vortex <vortex25@gmx.de>
To: pgsql-sql@postgresql.org
Subject: select within aggregate?
Date: Fri, 6 May 2005 09:25:35 +0200
Message-ID: <20050506092535.060bca35.vortex25@gmx.de> (raw)

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



view thread (5+ messages)  latest in thread

Message-ID: <20050506092535.060bca35.vortex25@gmx.de>
Permalink:  ../20050506092535.060bca35.vortex25@gmx.de/
Also on:    postgresql.org/message-id/20050506092535.060bca35.vortex25@gmx.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: vortex25@gmx.de
  Subject: Re: select within aggregate?
  In-Reply-To: <20050506092535.060bca35.vortex25@gmx.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox