pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Weimao Ke <wke@indiana.edu>
To: Daniel CAUNE <d.caune@free.fr>
Cc: pgsql-sql@postgresql.org
Subject: Re: pgsql aggregate: conditional max
Date: Sun, 12 Mar 2006 14:59:19 -0500
Message-ID: <44147D97.5050301@indiana.edu> (raw)
In-Reply-To: <0IW0005WSPTDIA40@VL-MH-MR002.ip.videotron.ca>
References: <0IW0005WSPTDIA40@VL-MH-MR002.ip.videotron.ca>

Daniel CAUNE wrote:

> SELECT aid, cat
>
>  FROM table, (
>    SELECT aid, max(weight) as weight
>      FROM table
>      GROUP BY aid) AS tablemaxweight
>  WHERE table.aid = tablemaxweight.aid
>    AND table.weight = tablemaxweight.aid;
>
>There is a limit case you don't specify how to deal with, when two or more categories have the same maximum weight.  The query I wrote retrieves all the categories that have the maximum weight, but perhaps you just want one per aid.
>  
>
Yes, this will introduce duplicates. Yet it is not too difficult to 
select only one for each aid from the results. Thank you!

Weimao

>--
>Daniel
>
>
>  
>


-- 
All best, 

Weimao

Weimao Ke
Indiana University Bloomington
School of Library and Information Science
http://ella.slis.indiana.edu/~wke




view thread (9+ messages)  latest in thread

Message-ID: <44147D97.5050301@indiana.edu>
Permalink:  ../44147D97.5050301@indiana.edu/
Also on:    postgresql.org/message-id/44147D97.5050301@indiana.edu

 · 

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: wke@indiana.edu, d.caune@free.fr
  Subject: Re: pgsql aggregate: conditional max
  In-Reply-To: <44147D97.5050301@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