Re: complex query

Поиск
Список
Период
Сортировка
От Scott Marlowe
Тема Re: complex query
Дата
Msg-id CAOR=d=09m_S2ykYGO6YJTpvFRBz=ZYo_Lha_S8VNsaJ+=yfeKw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: complex query  (Mark Fenbers <mark.fenbers@noaa.gov>)
Список pgsql-sql
On Sat, Oct 27, 2012 at 7:56 PM, Mark Fenbers <mark.fenbers@noaa.gov> wrote:
> I'd do somethings like:
>
> select * from (
>     select id, sum(col1), sum(col2) from tablename group by yada
>    ) as a [full, left, right, outer] join (
>     select id, sum(col3), sum(col4) from tablename group by bada
>     ) as b
> on (a.id=b.id);
>
> and choose the join type as appropriate.
>
> Thanks!  Your idea worked like a champ!
> Mark

The basic rules for mushing together data sets is to join them to put
the pieces of data into the same row (horiztonally extending the set)
and use unions to pile the rows one on top of the other.

One of the best things about PostgreSQL is that it's very efficient at
making these kinds of queries efficient and fast.  I've written 5 or 6
page multi-join multi-union queries that still ran in hundreds of
milliseconds, returning thousands of rows.



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

Предыдущее
От: Mark Fenbers
Дата:
Сообщение: Re: complex query
Следующее
От: "Oliveiros d'Azevedo Cristina"
Дата:
Сообщение: Re: complex query