Why Doesn't SQL This Expression Work?

From: "Lane Van Ingen" <lvaningen(at)esncc(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Why Doesn't SQL This Expression Work?
Date: 2005-08-22 19:50:37
Message-ID: EKEMKEFLOMKDDLIALABIAEKMCBAA.lvaningen@esncc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi, am trying to do a simple computation on two views, but for some reason
the current_util_in computation always returns zero. All fields being used
are integer.

select a.if_id,
a.in_count,
a.time_incr,
b.speed,
((a.time_incr * b.speed) / 8) as possible_bytes,
(a.in_count / ((a.time_incr * b.speed) / 8) * 100) AS current_util_in,
from if_history_view1 a, speed_history_view1 b
where a.if_id = b.if_id
and a.if_id = 2;

The inner computation (a.time_incr * b.speed / 8) evaluated properly to
7675200.
Add the "in_count divide operation", and the result is zero.

The result expected is a percentage, and should compute to 7.68 (8 as an
integer), when multiplied by 100. What is wrong here? Here is the result:
Row if_id in_count time_incr speed possible_bytes current_util_in
1 2 589824 240 255840 7675200 0

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Richard_D_Levine 2005-08-22 19:52:18 Re: PL/SQL Function: self-contained transaction?
Previous Message Greg Stark 2005-08-22 18:20:00 Re: PL/SQL Function: self-contained transaction?