Complicated GROUP BY

Поиск
Список
Период
Сортировка
От dgront
Тема Complicated GROUP BY
Дата
Msg-id b418e622-af2f-4218-bfb7-b2de9b3debca@l64g2000hse.googlegroups.com
обсуждение исходный текст
Ответы Re: Complicated GROUP BY  ("Adam Rich" <adam.r@sbcglobal.net>)
Re: Complicated GROUP BY  ("Hoover, Jeffrey" <jhoover@jcvi.org>)
Re: Complicated GROUP BY  ("Hoover, Jeffrey" <jhoover@jcvi.ORG>)
Список pgsql-general
Dear All,

I have the following problem with grouping: I want to know the maximum
in a group as well as the maximal element. Example:

I have a table products_providers:
product  |  provider  |  criteria_1  |  criteria_2

I have a number of products, each of them from a several providers.
Each product is described by two numeric values. I can easily select
the best value for each product by a given criteria, like:

select product, max(criteria_1) from products_providers group by
product;

but I need to know the best-scoring provider as well.

Result I need should look like:
product  |  best_provider_1  | best_criteria_1  |  best_provider_2  |
best_criteria_2

If it counts results may be split into two tables: one for the first
and the other for the second criteria

Can you help me with a painless solution?
Dominik

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

Предыдущее
От: Scott Frankel
Дата:
Сообщение: Re: roll back to 8.1 for PyQt driver work-around
Следующее
От: "Goldeneye Solutions Information"
Дата:
Сообщение: Feature: FOR UPDATE SKIP LOCKED