GROUP BY, ORDER & LIMIT ?

From: "Kynn Jones" <kynnjo(at)gmail(dot)com>
To: "pgsql-general General" <pgsql-general(at)postgresql(dot)org>
Subject: GROUP BY, ORDER & LIMIT ?
Date: 2008-05-06 17:22:30
Message-ID: c2350ba40805061022x3b487b59j63c7176ca065c19b@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Wilson 2008-05-06 17:55:14 Re: GROUP BY, ORDER & LIMIT ?
Previous Message Pau Marc Munoz Torres 2008-05-06 16:17:54 Re: select from an index