Re: If statements on select

Поиск
Список
Период
Сортировка
От Alvaro Herrera
Тема Re: If statements on select
Дата
Msg-id 20050415124841.GB31521@dcc.uchile.cl
обсуждение исходный текст
Ответ на If statements on select  ("Alejandro D. Burne" <alejandro.dburne@gmail.com>)
Список pgsql-general
On Fri, Apr 15, 2005 at 09:13:40AM -0300, Alejandro D. Burne wrote:
> Hi, I'm translating an app made with visual foxpro and mysql as rdbms
> to postgres.
> I've got many querys with this sintax:
>
> select code1, sum(if(cond1, price,0)), sum(if(cond2,price,0)) from ...

Use CASE WHEN cond1 THEN price ELSE 0 END.

But note that if your condition is to test price for NULL, it's easier to do

COALESCE(price, 0)

--
Alvaro Herrera (<alvherre[@]dcc.uchile.cl>)
"El día que dejes de cambiar dejarás de vivir"

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

Предыдущее
От: "GIROIRE, Nicolas (COFRAMI)"
Дата:
Сообщение: Re: SQL Question
Следующее
От: Richard Huxton
Дата:
Сообщение: Re: SQL Question