pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: computing z-scores
Date: Thu, 24 May 2018 10:26:44 -0500
Message-ID: <a220c1bf-ab2b-d230-7526-442716f3db5f@gmail.com> (raw)
In-Reply-To: <2CC1AFF5-BB3A-499D-8969-C5B3388ED534@northwestern.edu>
References: <2CC1AFF5-BB3A-499D-8969-C5B3388ED534@northwestern.edu>

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


-- 
Angular momentum makes the world go 'round.




view thread (5+ messages)  latest in thread

Message-ID: <a220c1bf-ab2b-d230-7526-442716f3db5f@gmail.com>
Permalink:  ../a220c1bf-ab2b-d230-7526-442716f3db5f@gmail.com/
Also on:    postgresql.org/message-id/a220c1bf-ab2b-d230-7526-442716f3db5f@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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: ronljohnsonjr@gmail.com
  Subject: Re: computing z-scores
  In-Reply-To: <a220c1bf-ab2b-d230-7526-442716f3db5f@gmail.com>
  References: <2CC1AFF5-BB3A-499D-8969-C5B3388ED534@northwestern.edu> <a220c1bf-ab2b-d230-7526-442716f3db5f@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