Re: Math Query Help

Поиск
Список
Период
Сортировка
От
Тема Re: Math Query Help
Дата
Msg-id 20060509221753.90980.qmail@web33315.mail.mud.yahoo.com
обсуждение исходный текст
Ответ на Re: Math Query Help  (George Weaver <gweaver@shaw.ca>)
Список pgsql-novice
> ----- Original Message -----
> From: <operationsengineer1@yahoo.com>
> To: <pgsql-novice@postgresql.org>
> Sent: Tuesday, May 09, 2006 3:59 PM
> Subject: [NOVICE] Math Query Help
>
>
> > (select count(inspect_pass) from t_inspect where
> > inspect_pass = true)/(select count(inspect_pass)
> from
> > t_inspect)
> >
> > i get the following error:
> >
> > ERROR:  syntax error at or near "/" at character
> 70
> >
> > how can i fix this?
>
> This should work:
>
> SELECT((select count(inspect_pass) from t_inspect
> where
> inspect_pass = true)/(select count(inspect_pass)
> from
>  t_inspect))
>
> Regards,
> George

George, this format does run, but for other newbs out
there, it will yield a result of 0 unless you cast the
results as numeric like so:

SELECT(
  (select count(inspect_pass)
  from t_inspect
  where inspect_pass = true)::numeric
  /
  (select count(inspect_pass)
  from t_inspect)::numeric
)::numeric(10,2)

in my case, this returns 0.64

thanks for sharing this syntax.  my searches were all
coming up empty.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

В списке pgsql-novice по дате отправления:

Предыдущее
От: "Andrej Ricnik-Bay"
Дата:
Сообщение: Re: Math Operations - DB or App?
Следующее
От:
Дата:
Сообщение: Re: Math Operations - DB or App?