Select first ten of each category?

Поиск
Список
Период
Сортировка
От Benjamin Smith
Тема Select first ten of each category?
Дата
Msg-id 200604121816.09941.lists@benjamindsmith.com
обсуждение исходный текст
Ответы Re: Select first ten of each category?  (Yanni Chiu <yanni@rogers.com>)
Re: Select first ten of each category?  (Michael Glaesemann <grzm@myrealbox.com>)
Re: Select first ten of each category?  (Brent Wood <b.wood@niwa.co.nz>)
Re: Select first ten of each category?  ("Dawid Kuroczko" <qnex42@gmail.com>)
Список pgsql-general
I'm stumped on this one...

I have a table defined thusly:

create table items (
id serial,
category integer not null references category(id),
name varchar not null,
price real,
unique(category, name));

It has a LARGE number of entries. I'd like to grab the 10 most expensive items
from each category in a single query. How can this be done? Something like

Select items.*
FROM items
where id IN (
    select firstTen(id) FROM items
    group by category
    ORDER BY price DESC
    )
ORDER BY price desc;

But I've not found any incantation to make this idea work...

-Ben
--
"The best way to predict the future is to invent it."
- XEROX PARC slogan, circa 1978

В списке pgsql-general по дате отправления:

Предыдущее
От: "Merlin Moncure"
Дата:
Сообщение: Re: Leverage your PostgreSQL V8.1 skills to learn DB2
Следующее
От: Yanni Chiu
Дата:
Сообщение: Re: Select first ten of each category?