getting around---division by zero on numeric

Поиск
Список
Период
Сортировка
От Tim Nelson
Тема getting around---division by zero on numeric
Дата
Msg-id 43563B8D.7070506@phreaker.net
обсуждение исходный текст
Ответы Re: getting around---division by zero on numeric  (Sean Davis <sdavis2@mail.nih.gov>)
Re: getting around---division by zero on numeric  (Richard Huxton <dev@archonet.com>)
Re: getting around---division by zero on numeric  (Andreas Kretschmer <akretschmer@spamfence.net>)
Re: getting around---division by zero on numeric  (Michael Glaesemann <grzm@myrealbox.com>)
Re: getting around---division by zero on numeric  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
I am getting division by zero on a calculated field ( sum(sales) is 0 )
and I can't find a way around this.  I figured out you can't use an
aggregate in a where, and using having the parser must (obviously)
evaluate the select fields before considering teh having clause.

Does anyone have a way around this?  Thanks!

select
    type,
    sum(sales),
    sum(cost),
    (sum(sales) * sum(cost) / sum(sales)) * 100
from test
group by 1
having sum(sales) != 0


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

Предыдущее
От: Vittorio
Дата:
Сообщение: psql runs out of memory
Следующее
От: "Marcel Gsteiger"
Дата:
Сообщение: function that resolves IP addresses