Re: can these queries be combined into one?

Поиск
Список
Период
Сортировка
От Jasen Betts
Тема Re: can these queries be combined into one?
Дата
Msg-id jkmjj6$fhv$1@reversiblemaps.ath.cx
обсуждение исходный текст
Ответ на can these queries be combined into one?  (hamann.w@t-online.de)
Список pgsql-general
On 2012-03-25, hamann.w@t-online.de <hamann.w@t-online.de> wrote:
>
>
> Hi,
>
> I am currently doing something like
>
> select ordercode, descr, codes into temp table x from products where ...
> Here codes is a bit-mapped field
> update x set codes = codes | 512 from othertable t where ordercode = t.ordercode and ....
> select * from x

basically what you do is do a join and put some expressions in the
select list.  I used coalesce here as it was a better fit, but case
can also be used...


perhaps this: (needs procucts to have a primary key whih will need to
be substituted in)

select distinct on ( p.PRIMARYY_KEY )
    coalesce( t.ordercode|512, p.orderecode ) as ordercode ,
    p.descr, p.codes
  from products as p
    left outer join othertable as t
      on p.ordercode = t.ordercode and ....
    where ... ;





--
⚂⚃ 100% natural

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

Предыдущее
От: Guillaume Lelarge
Дата:
Сообщение: Re: can these queries be combined into one?
Следующее
От: Guillaume Lelarge
Дата:
Сообщение: Re: can these queries be combined into one?