Re: computing z-scores

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: computing z-scores
Дата
Msg-id CAKFQuwZP1JiUTL5DqzNMQMOw8cpgCjejo-AjXeLB3RQkb8wCWw@mail.gmail.com
обсуждение исходный текст
Ответ на computing z-scores  (Martin Mueller <martinmueller@northwestern.edu>)
Ответы Re: computing z-scores  ("David G. Johnston" <david.g.johnston@gmail.com>)
Re: computing z-scores  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-general
On Thu, May 24, 2018 at 8:15 AM, Martin Mueller <martinmueller@northwestern.edu> 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. 

Window functions provide the easiest means to apply aggregated values to individual rows.

SELECT v, (v - (AVG(v) OVER ()) / (stddev(v) OVER ())) AS z_v 
FROM  (
VALUES (1),(2),(3)
) vals (v);

//-1, 0, 1


David J.

В списке pgsql-general по дате отправления:

Предыдущее
От: Maxim Boguk
Дата:
Сообщение: Re: found xmin from before relfrozenxid on pg_catalog.pg_authid
Следующее
От: Ron
Дата:
Сообщение: Re: computing z-scores