From: Markus Schaber <schabi@logix-tt.com>
To: Weimao Ke <wke@indiana.edu>
Cc: Michael Fuhr <mike@fuhr.org>
Cc: pgsql-sql@postgresql.org
Subject: Re: pgsql aggregate: conditional max
Date: Mon, 27 Mar 2006 16:14:41 +0200
Message-ID: <4427F351.5010303@logix-tt.com> (raw)
In-Reply-To: <44145569.3010208@indiana.edu>
References: <4413AD1C.9050604@indiana.edu>
<20060312054212.GA25423@winnie.fuhr.org>
<44145569.3010208@indiana.edu>
Hi, Weimao Ke,
Weimao Ke wrote:
>> 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...:)
Try
SELECT DISTINCT aid, cat
FROM tablename AS t
JOIN (SELECT aid, max(weight) AS weight
FROM tablename
GROUP BY aid) AS s USING (aid, weight);
HTH,
Markus
--
Markus Schaber | Logical Tracking&Tracing International AG
Dipl. Inf. | Software Development GIS
Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org
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: schabi@logix-tt.com, wke@indiana.edu, mike@fuhr.org
Subject: Re: pgsql aggregate: conditional max
In-Reply-To: <4427F351.5010303@logix-tt.com>
* 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