Re: Fwd: Ask for a question - Mailing list pgsql-general

From Paul Jungwirth
Subject Re: Fwd: Ask for a question
Date
Msg-id CA+6hpakr7hTk6vxKWuj8URYEohrSD9K3TSGDkYcLWzAekJLnfQ@mail.gmail.com
Whole thread Raw
In response to Re: Fwd: Ask for a question  (Paul Jungwirth <pj@illuminatedcomputing.com>)
List pgsql-general
Oh sorry, you should leave off the grouping:

select stddev(a), stddev(b), stddev(c) from foo;

Paul

On Wed, Jan 21, 2015 at 10:24 AM, Paul Jungwirth
<pj@illuminatedcomputing.com> wrote:
> Hi Pierre,
>
> Looking at your Excel document I think I misinterpreted, and you are
> trying to take the stddev of each column separately (which makes a lot
> more sense!). In the case you can say this:
>
> select id, stddev(a), stddev(b), stddev(c) from foo group by id;
>
> Paul
>
>
> On Wed, Jan 21, 2015 at 10:15 AM, Paul Jungwirth
> <pj@illuminatedcomputing.com> wrote:
>> Hi Pierre,
>>
>> It looks like you're saying that each row has an id plus three numeric
>> columns, and you want the stddev calculated from the three numeric
>> columns? In that case you could do this:
>>
>> create table foo (id integer, a float, b float, c float);
>> insert into foo values (1, 2,3,4);
>> insert into foo values (2, 2,3,4);
>> select id, stddev(x) from (select id, unnest(array[a,b,c]) x from foo)
>> bar group by id;
>>  id | stddev
>> ----+--------
>>   1 |      1
>>   2 |      1
>> (2 rows)
>>
>> But if that's correct, then I think your table is badly structured for
>> a relational database. It might be better to have just two columns: an
>> id and *one* numeric value. Or perhaps an id and an array of numeric
>> values if you really want all values in one row.
>>
>> At a higher level, if you are really taking the stddev of a sample of
>> size 3, you should reconsider applying statistical analysis to your
>> problem at all.
>>
>> I hope this helps!
>>
>> Paul
>>
>>
>>
>>
>>
>>
>>
>>
>> On Wed, Jan 21, 2015 at 10:09 AM, Raymond O'Donnell <rod@iol.ie> wrote:
>>> On 21/01/2015 18:02, Pierre Hsieh wrote:
>>>> Hi Raymond,
>>>>
>>>> Thanks for your reply. Please see detail as following. Thanks again.
>>>
>>> Can you describe *in words* what sort of calculation you want to do?
>>>
>>> Ray.
>>>
>>>
>>> --
>>> Raymond O'Donnell :: Galway :: Ireland
>>> rod@iol.ie
>>>
>>>
>>> --
>>> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
>>> To make changes to your subscription:
>>> http://www.postgresql.org/mailpref/pgsql-general
>>
>>
>>
>> --
>> _________________________________
>> Pulchritudo splendor veritatis.
>
>
>
> --
> _________________________________
> Pulchritudo splendor veritatis.



--
_________________________________
Pulchritudo splendor veritatis.


pgsql-general by date:

Previous
From: Paul Jungwirth
Date:
Subject: Re: Fwd: Ask for a question
Next
From: Pierre Hsieh
Date:
Subject: Re: Fwd: Ask for a question