Re: Math Query Help - Mailing list pgsql-novice

From
Subject Re: Math Query Help
Date
Msg-id 20060509221753.90980.qmail@web33315.mail.mud.yahoo.com
Whole thread Raw
In response to Re: Math Query Help  (George Weaver <gweaver@shaw.ca>)
List 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 by date:

Previous
From: "Andrej Ricnik-Bay"
Date:
Subject: Re: Math Operations - DB or App?
Next
From:
Date:
Subject: Re: Math Operations - DB or App?