pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedFractional Results
2+ messages / 2 participants
[nested] [flat]
* Fractional Results
@ 2002-02-02 01:26 Paulo J. Matos <pocm@rnl.ist.utl.pt>
2002-02-02 04:39 ` Re: Fractional Results Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 2+ messages in thread
From: pocm@rnl.ist.utl.pt @ 2002-02-02 01:26 UTC (permalink / raw)
To: pgsql-sql
Hi all,
I'm doing a sql query to get an average of some tables. SQL has
an average command but unfortunately we cannot use it since out
information is not in only one column, we've done the following:
select temp1.espl / temp2.iluminados
from (select count(*) as espl from esp) as temp1,
(select count(distinct id) as iluminados from esp) as temp2;
After some testing i found out that temp1.espl / temp2.iluminados
gives us always the floor of the real value. I would like the
fractional number instead of the floor.
Any ideas on this topic?
Best regards,
--
Paulo J. Matos : pocm(_at_)rnl.ist.utl.pt
Instituto Superior Tecnico - Lisbon
Software & Computer Engineering - A.I.
- > http://www.rnl.ist.utl.pt/~pocm
---
Yes, God had a deadline...
So, He wrote it all in Lisp!
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Fractional Results
2002-02-02 01:26 Fractional Results Paulo J. Matos <pocm@rnl.ist.utl.pt>
@ 2002-02-02 04:39 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2002-02-02 04:39 UTC (permalink / raw)
To: pocm@rnl.ist.utl.pt; +Cc: pgsql-sql
pocm@rnl.ist.utl.pt (Paulo J. Matos) writes:
> After some testing i found out that temp1.espl / temp2.iluminados
> gives us always the floor of the real value.
If these are integers, try casting them to floats before dividing.
Integer division is generally understood to yield the floor().
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2002-02-02 04:39 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-02-02 01:26 Fractional Results Paulo J. Matos <pocm@rnl.ist.utl.pt>
2002-02-02 04:39 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox