Re: pgsql aggregate: conditional max

From: Weimao Ke <wke(at)indiana(dot)edu>
To: Michael Fuhr <mike(at)fuhr(dot)org>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: pgsql aggregate: conditional max
Date: 2006-03-12 17:07:53
Message-ID: 44145569.3010208@indiana.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Robert Paulsen 2006-03-12 17:11:17 Question re: relational technique
Previous Message Weimao Ke 2006-03-12 16:55:01 Re: pgsql aggregate: conditional max