Re: [SQL] sql question: min remapped value

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [SQL] sql question: min remapped value
Дата
Msg-id 358.942972233@sss.pgh.pa.us
обсуждение исходный текст
Ответ на sql question: min remapped value  (Douglas Nichols <dnichols@fhcrc.org>)
Список pgsql-sql
Douglas Nichols <dnichols@fhcrc.org> writes:
> I was looking at something like
> select id, field1, min(decode(field1,1,1,0,2,3,4,4,5,0)) as flag
>   from mydata
>   group by id;

Postgres doesn't have DECODE (nor is it in the SQL standard), but
you can get the effect you want with a CASE expression.  Note that
CASE is rather buggy in pre-6.5.2 releases, so update if you haven't
lately.

PS: you won't be able to access field1 outside the MIN() if you have
"group by id" as shown.
        regards, tom lane


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

Предыдущее
От: Douglas Nichols
Дата:
Сообщение: sql question: min remapped value
Следующее
От: Haris Susanto
Дата:
Сообщение: Backend message type 0x45 arrived while idle