sum divided by count ends in zero

From: "Dara Olson" <dolson(at)glifwc(dot)org>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: sum divided by count ends in zero
Date: 2009-11-24 22:32:10
Message-ID: 9142E564EC00401CAA28CF1C90E52901@GISWKSTN
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Greetings.

I am having a problem dividing a sum by a count and end up with zero, however I am able to multiply, subtract and add.

Here are samples of the two views:
View that groups individuals into specific groups by numbers:
SELECT
SUM(CASE when indiv_total_lbs <= 50 then 1 else 0 end) as "0_50",
SUM(CASE when indiv_total_lbs <= 100 AND indiv_total_lbs > 50 then 1 else 0 end) as "51_100", etc.
FROM wr_harvest.sh_sum_by_harvestor

View that gathers overall stats:
SELECT
AVG (indiv_total_trips) AS ave_no_trips, etc.
COUNT(DISTINCT x) AS no_harvestors, etc.
FROM wr_harvest.sh_sum_by_harvestor

I want to find the percent of individuals in each catagory from the first view.
SELECT
a."0_50"/b.no_harvestors *100 AS "0_50percent",
a."51_100"/b.no_harvestors *100 AS "51_100percent", etc
FROM wr_harvest.sh_distribution_stats_no as a, wr_harvest.sh_harvestor_stats as b

I am able to add, subtract and mulitply the values with the correct outcomes, but every time I try to divide the two numbers I end in zero.
What am I doing wrong? Any help would be greatly appreciated.

Miigwech in advance!
Dara

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Syan Tan 2009-11-25 03:47:13 Re: Postgres blob question - insert from basic.
Previous Message Tom Lane 2009-11-24 19:24:51 Re: Internal time stamps?