getting around---division by zero on numeric

From: Tim Nelson <timnelson(at)phreaker(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: getting around---division by zero on numeric
Date: 2005-10-19 12:26:53
Message-ID: 43563B8D.7070506@phreaker.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Terry Fielder 2005-10-19 12:26:58 Re: [GENERAL] Oracle buys Innobase
Previous Message Marius Cornea 2005-10-19 12:08:15 Create GLOBAL TABLE