pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Billy G. Allie <Bill.Allie@mug.org>
To: Hannu Krosing <hannu@trust.ee>
Cc: rodneyr@embratel.com.br
Cc: pgsql-interfaces@hub.org
Cc: bga@mug.org
Subject: Re: [INTERFACES] AVG function
Date: Sat, 28 Aug 1999 14:16:16 -0400
Message-ID: <199908281816.OAA19438@bajor.mug.org> (raw)
In-Reply-To: <37C804D3.BB1B63AA@trust.ee>

Hannu Krosing wrote:
> rodneyr@embratel.com.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.Allie@mug.org
|  /|      | 7436 Hartwell     | Compuserve: 76337,2061
|-/-|----- | Dearborn, MI 48126| MSN.......: B_G_Allie@email.msn.com
|/  |LLIE  | (313) 582-1540    | 

view thread (4+ messages)  latest in thread

Message-ID: <199908281816.OAA19438@bajor.mug.org>
Permalink:  ../199908281816.OAA19438@bajor.mug.org/
Also on:    postgresql.org/message-id/199908281816.OAA19438@bajor.mug.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: Bill.Allie@mug.org, hannu@trust.ee, rodneyr@embratel.com.br, pgsql-interfaces@hub.org, bga@mug.org
  Subject: Re: [INTERFACES] AVG function
  In-Reply-To: <199908281816.OAA19438@bajor.mug.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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