Re: Advanced Query

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: Advanced Query
Дата
Msg-id 20060602174325.GA2073@winnie.fuhr.org
обсуждение исходный текст
Ответ на Re: Advanced Query  (Michael Fuhr <mike@fuhr.org>)
Список 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 по дате отправления:

Предыдущее
От: "Aaron Bono"
Дата:
Сообщение: Re: Am I crazy or is this SQL not possible
Следующее
От:
Дата:
Сообщение: Using Query Result in WHERE Clause