Skip site navigation (1) Skip section navigation (2)

Re: Math Query Help

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 (view raw or flat)
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 

In response to

pgsql-novice by date

Next:From: operationsengineer1Date: 2006-05-09 22:23:29
Subject: Re: Math Operations - DB or App?
Previous:From: Andrej Ricnik-BayDate: 2006-05-09 21:55:37
Subject: Re: Math Operations - DB or App?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group