getting around---division by zero on numeric - Mailing list 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 by date:

Previous
From: Vittorio
Date:
Subject: psql runs out of memory
Next
From: "Marcel Gsteiger"
Date:
Subject: function that resolves IP addresses