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

Re: avg() from multiple columns

From: Jason Tan <jason(at)rebel(dot)rebel(dot)net(dot)au>
To: Miia Uski <miia(dot)uski(dot)155(at)student(dot)lu(dot)se>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: avg() from multiple columns
Date: 2001-09-05 03:02:31
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice

If you want row by row averages try this:

select (col1+col2+col3)/3 from table;

If you wnat to average several columns over the whole table this seems to

select avg(col1+col2+col3) from table;


On Sun, 2 Sep 2001, Miia Uski wrote:

> I have a question regarding taking the average value from several
> columns.
> I am trying to evaluate a survey with sql. I have one column per
> question, and one row per answered survey. The answers can have values 1
> - 4, unanswered questions have 0. I want to take the average from the
> answers of several questions that belong to the same category. For one
> question I can do like this:
> igv=> select avg("1.2") from igvdata
> igv-> where "1.2" > 0;
> How do I go about to have averages for several columns? Do I have to
> create views in order to avoid the "no answer"-values for each column?
> Thanks in advance,
> Miia
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org

Jason Tan                                                jason(at)rebel(dot)net(dot)au
     "Democracy is two wolves and a lamb voting on what to have for lunch. 
                 Liberty is a well-armed lamb contesting the vote."
                               ~Benjamin Franklin, 1759

In response to

pgsql-novice by date

Next:From: Jason TanDate: 2001-09-05 05:23:47
Subject: Re: pl/pgsql recursion/arrays (fwd)
Previous:From: brewDate: 2001-09-04 23:22:10
Subject: Re: how to easily reduce permissions?

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