From: | <operationsengineer1(at)yahoo(dot)com> |
---|---|
To: | George Weaver <gweaver(at)shaw(dot)ca>, pgsql-novice(at)postgresql(dot)org |
Subject: | Re: Math Query Help |
Date: | 2006-05-09 22:17:53 |
Message-ID: | 20060509221753.90980.qmail@web33315.mail.mud.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
> ----- Original Message -----
> From: <operationsengineer1(at)yahoo(dot)com>
> To: <pgsql-novice(at)postgresql(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | operationsengineer1 | 2006-05-09 22:23:29 | Re: Math Operations - DB or App? |
Previous Message | Andrej Ricnik-Bay | 2006-05-09 21:55:37 | Re: Math Operations - DB or App? |