| From: | Michael Fuhr <mike(at)fuhr(dot)org> |
|---|---|
| To: | operationsengineer1(at)yahoo(dot)com |
| Cc: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: Advanced Query |
| Date: | 2006-06-02 17:43:25 |
| Message-ID: | 20060602174325.GA2073@winnie.fuhr.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
On Fri, Jun 02, 2006 at 10:09:01AM -0700, operationsengineer1(at)yahoo(dot)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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | operationsengineer1 | 2006-06-02 20:06:40 | Using Query Result in WHERE Clause |
| Previous Message | Aaron Bono | 2006-06-02 15:23:30 | Re: Am I crazy or is this SQL not possible |