Re: Advanced Query - Mailing list pgsql-sql

From Michael Fuhr
Subject Re: Advanced Query
Date
Msg-id 20060602174325.GA2073@winnie.fuhr.org
Whole thread Raw
In response to Re: Advanced Query  (Michael Fuhr <mike@fuhr.org>)
List pgsql-sql
On Fri, Jun 02, 2006 at 10:09:01AM -0700, operationsengineer1@yahoo.com wrote:
> Michael, my derivative of your query example works
> great - thank you!
> 
> i think i understand everything except why multiplying
> by 1.0 is necessary.  when i take it out, my expected
> result, 0.50000000000..., turns into 0 - so i assume
> it has to do with formatting the result.

Integer division yields integers, so 1 / 2 = 0 whereas 1.0 / 2.0 = 0.5.
The expression therefore needs something to force a non-integer result.
Multiplying by 1.0 (or 100.0) is one way; using 1.0 and 0.0 in the CASE
expression is another; casting one of the operands to numeric or one of
the floating-point types is yet another.

-- 
Michael Fuhr


pgsql-sql by date:

Previous
From: "Aaron Bono"
Date:
Subject: Re: Am I crazy or is this SQL not possible
Next
From:
Date:
Subject: Using Query Result in WHERE Clause