pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Aaron Bono <postgresql@aranya.com>
To: Raghuraman K <raghuramank@aztecsoft.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Distribution of results
Date: Tue, 7 Nov 2006 08:59:08 -0600
Message-ID: <bf05e51c0611070659q5fca28b9ue70c0a5b749d8b3e@mail.gmail.com> (raw)
In-Reply-To: <93F0E3CFC1ABB646B8808894FC7CDD25067221E2@azindbaex01.aztec.soft>
References: <93F0E3CFC1ABB646B8808894FC7CDD25067221E2@azindbaex01.aztec.soft>

On 11/1/06, Raghuraman K <raghuramank@aztecsoft.com> wrote:
>
> Hi,
>
>    I have a table like this: create table(xyz char(10), answer
> number(4)).  There are a lot of rows in this table. I am looking at a query
> that will help me represent the distribution of data records based on the
> column answer. For example, we may take that the highest entry for answer
> column is 90 and the lowest is 2 and there are 1000 records. I am looking at
> a query that will tell how the 1000 records are distributed between the
> highest and lowest answer (in this case between 90 and 2).  Can anyone
> please help?
>


It helps to know what kind of distribution information you are after.

Mean:
select sum(number) / count(*) from xyz;

Median:
Check out this URL
http://72.14.203.104/search?q=cache:kvZMBQuoAbkJ:people.planetpostgresql.org/greg/index.php%3F/categ...

Range:
select max(number) - min(number) from xyz;

Population Variance:
select power(sum(number - mean), 2) / count(*)
from xyz
inner join (
select sum(number) / count(*) as mean from xyz
) as xyz_mean
;

Sample Variance:
select power(sum(number - mean), 2) / (count(*) - 1)
from xyz
inner join (
select sum(number) / count(*) as mean from xyz
) as xyz_mean
;

Note that I did not check the syntax for typos.

Anything more than this will require you whip out a Statistics book.

==================================================================
   Aaron Bono
   Aranya Software Technologies, Inc.
   http://www.aranya.com
   http://codeelixir.com
==================================================================

view thread (4+ messages)

Message-ID: <bf05e51c0611070659q5fca28b9ue70c0a5b749d8b3e@mail.gmail.com>
Permalink:  ../bf05e51c0611070659q5fca28b9ue70c0a5b749d8b3e@mail.gmail.com/
Also on:    postgresql.org/message-id/bf05e51c0611070659q5fca28b9ue70c0a5b749d8b3e@mail.gmail.com

 · 

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-sql@postgresql.org
  Cc: postgresql@aranya.com, raghuramank@aztecsoft.com
  Subject: Re: Distribution of results
  In-Reply-To: <bf05e51c0611070659q5fca28b9ue70c0a5b749d8b3e@mail.gmail.com>

* 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