On Wed, 5 Mar 2003 17:02:42 +0100, "Peter Alberer"
<h9351252@obelix.wu-wien.ac.at> wrote:
>How can I filter the output to only return the top values per area? I
>would prefer not to use stored-procedures or client-side code if that is
>not necessary.
Peter,
DISTINCT ON is your friend. I never tried to use it together with
GROUP BY; at least you can use your original query as a sub-select
and wrap the DISTINCT ON query around it.
SELECT DISTINCT ON (area) area, user_id, total, succ
FROM (SELECT ...) AS t
ORDER BY area, succ DESC, total DESC;
Servus
Manfred