GROUP BY, ORDER & LIMIT ? - Mailing list pgsql-general

From Kynn Jones
Subject GROUP BY, ORDER & LIMIT ?
Date
Msg-id c2350ba40805061022x3b487b59j63c7176ca065c19b@mail.gmail.com
Whole thread Raw
Responses Re: GROUP BY, ORDER & LIMIT ?  ("David Wilson" <david.t.wilson@gmail.com>)
Re: GROUP BY, ORDER & LIMIT ?  (hubert depesz lubaczewski <depesz@depesz.com>)
List pgsql-general




Suppose table X has two columns: class (TEXT) and size (INT).  I want a listing showing the (up to) 5 largest values of "size" for each value of "class" (for some values of "class" the total number of available records may be less than 5).

What would be the simplest way to achieve such a listing?  It seems like something one could do with GROUP BY, ORDER, and LIMIT, but I can't figure out the right syntax for this query.

Thanks!

Kynn

pgsql-general by date:

Previous
From: Martijn van Oosterhout
Date:
Subject: Re: more custom C function fun
Next
From: "David Wilson"
Date:
Subject: Re: GROUP BY, ORDER & LIMIT ?