From: | "Billy G(dot) Allie" <Bill(dot)Allie(at)mug(dot)org> |
---|---|
To: | Hannu Krosing <hannu(at)trust(dot)ee> |
Cc: | rodneyr(at)embratel(dot)com(dot)br, pgsql-interfaces(at)hub(dot)org, bga(at)mug(dot)org |
Subject: | Re: [INTERFACES] AVG function |
Date: | 1999-08-28 18:16:16 |
Message-ID: | 199908281816.OAA19438@bajor.mug.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-interfaces |
Hannu Krosing wrote:
> rodneyr(at)embratel(dot)com(dot)br wrote:
> >
> > I'm using the AVG function to get the average of some integer values of my
> > database,
> > but the result is comming in the integer format too, and I'm loosing some
> > precision.
> >
> > Does someone know how to get the result of the AVG function in a float type,
> > without
> > changing the structure of my table?
>
> Try this:
>
> hannu=> select * from t;
> i
> -
> 4
> 4
> 4
> 4
> 3
> (5 rows)
>
> hannu=> select avg(i * 1.0) from t;
> avg
> ---
> 3.8
> (1 row)
>
Actually, this will work without the need for a multiplication:
bga=> select * from t;
i
-
1
2
3
4
5
6
(6 rows)
bga=> select AVG(i::float) from t;
avg
---
3.5
(1 row)
--
____ | Billy G. Allie | Domain....: Bill(dot)Allie(at)mug(dot)org
| /| | 7436 Hartwell | Compuserve: 76337,2061
|-/-|----- | Dearborn, MI 48126| MSN.......: B_G_Allie(at)email(dot)msn(dot)com
|/ |LLIE | (313) 582-1540 |
From | Date | Subject | |
---|---|---|---|
Next Message | Hannu Krosing | 1999-08-28 20:54:02 | Re: [INTERFACES] AVG function |
Previous Message | Spirou | 1999-08-28 16:29:25 | [Fwd: bug ? get_groname: group 0 not found] |