From: Weimao Ke <wke@indiana.edu>
To: Michael Fuhr <mike@fuhr.org>
Cc: pgsql-sql@postgresql.org
Subject: Re: pgsql aggregate: conditional max
Date: Sun, 12 Mar 2006 12:07:53 -0500
Message-ID: <44145569.3010208@indiana.edu> (raw)
In-Reply-To: <20060312054212.GA25423@winnie.fuhr.org>
References: <4413AD1C.9050604@indiana.edu>
<20060312054212.GA25423@winnie.fuhr.org>
Michael Fuhr wrote:
>SELECT DISTINCT ON (aid) aid, cat
>FROM tablename
>ORDER BY aid, weight DESC, cat;
>
>
Good pointer. I think this will solve my problem. :)
>SELECT aid, cat
>FROM tablename AS t
>JOIN (SELECT aid, max(weight) AS weight
> FROM tablename
> GROUP BY aid) AS s USING (aid, weight);
>
>
This query will return duplicates if there are multiple categories (for
one aid) with the same max weight. Yet, I should be able to remove the
duplicates somehow...:)
I really appreciate your help!
--
All best,
Weimao
Weimao Ke
Indiana University Bloomington
School of Library and Information Science
http://ella.slis.indiana.edu/~wke
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: wke@indiana.edu, mike@fuhr.org
Subject: Re: pgsql aggregate: conditional max
In-Reply-To: <44145569.3010208@indiana.edu>
* 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