Received: from localhost (pluto.hub.org [200.46.204.4]) by postgresql.org (Postfix) with ESMTP id 94BE69FA433 for ; Tue, 7 Nov 2006 10:59:14 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.4]) (amavisd-new, port 10024) with ESMTP id 34268-09 for ; Tue, 7 Nov 2006 10:59:07 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.231]) by postgresql.org (Postfix) with ESMTP id B842E9FA22A for ; Tue, 7 Nov 2006 10:59:11 -0400 (AST) Received: by wr-out-0506.google.com with SMTP id 55so314744wri for ; Tue, 07 Nov 2006 06:59:09 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:references:x-google-sender-auth; b=GtXRrmpqxOxwleczZdidlYtUvyPYSoTZQuaFGJDx/aBbpAMjy7vK9GBLD30tG799v8fUXV7egqnxNz65QSrIfxQgP8pB63pX1COxk0IAiuuEWS0yE1Oef3eKlH6ArMmZht6hO8S+RLKc1Tu3+ETnn9Q3IA4XEuLUzl7kw2c9qxI= Received: by 10.78.180.18 with SMTP id c18mr8351276huf.1162911548347; Tue, 07 Nov 2006 06:59:08 -0800 (PST) Received: by 10.78.136.6 with HTTP; Tue, 7 Nov 2006 06:59:08 -0800 (PST) Message-ID: Date: Tue, 7 Nov 2006 08:59:08 -0600 From: "Aaron Bono" To: "Raghuraman K" Subject: Re: Distribution of results Cc: pgsql-sql@postgresql.org In-Reply-To: <93F0E3CFC1ABB646B8808894FC7CDD25067221E2@azindbaex01.aztec.soft> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_5345_18265050.1162911548221" References: <93F0E3CFC1ABB646B8808894FC7CDD25067221E2@azindbaex01.aztec.soft> X-Google-Sender-Auth: 0220370e2ee3e737 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/100 X-Sequence-Number: 26752 ------=_Part_5345_18265050.1162911548221 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 11/1/06, Raghuraman K 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/categories/13-Math+postgresql+median+mean+functions&hl=en&gl=us&ct=clnk&cd=1&client=firefox-a 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 ================================================================== ------=_Part_5345_18265050.1162911548221 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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/categories/13-Math+postgresql+median+mean+functions&hl=en&gl=us&ct=clnk&cd=1&client=firefox-a

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
================================================================== ------=_Part_5345_18265050.1162911548221--