Re: computing z-scores - Mailing list pgsql-general

From David G. Johnston
Subject Re: computing z-scores
Date
Msg-id CAKFQuwYZ=uC0VkE-RLwehd-DOumVkdfmcWoSpK-fF_igCGEbmw@mail.gmail.com
Whole thread Raw
In response to Re: computing z-scores  (Ron <ronljohnsonjr@gmail.com>)
List pgsql-general
On Thursday, May 24, 2018, Ron <ronljohnsonjr@gmail.com> wrote:
On 05/24/2018 10:15 AM, Martin Mueller wrote:
You construct a z-score for a set of values by subtracting the average from the value and dividing the result by the standard deviation. I know how to do this in a two-step procedure. First, I compute the average and standard deviation. In a second run I use the formula and apply it to each value.

Is there a way of doing this in a single-step procedure or can you chain the two parts together in one query?  This goes beyond my SQL competence.

What about this?

SELECT value, (value - AVG(value))/stddev(value) as zvalue
FROM sometable
WHERE some conditions
GROUP by value

That is syntactically correct but doesn't provide the correct answer.

David J. 

pgsql-general by date:

Previous
From: Ron
Date:
Subject: Re: computing z-scores
Next
From: "David G. Johnston"
Date:
Subject: Re: computing z-scores