Re: user defined aggregate for percentile calculations - Mailing list pgsql-general

From A. Kretschmer
Subject Re: user defined aggregate for percentile calculations
Date
Msg-id 20090406085328.GA8320@a-kretschmer.de
Whole thread Raw
In response to user defined aggregate for percentile calculations  (Kashmir <kashmir_us_1999@yahoo.com>)
Responses Re: user defined aggregate for percentile calculations
List pgsql-general
In response to Kashmir :
>
> cant seem to find anything about this,
> would it possible at all to create a percentile-aggregate in pgres?
> any pointers?
> tia
> -k

I'm not sure if i understand your problem, but how about:

test=*# select * from percentile ;
 id | value
----+-------
  1 |    10
  2 |    20
  3 |    30
  4 |    50
(4 rows)

test=*# select a.id, a.value, (a.value*100/foo.summe)::numeric(10,2)
from percentile a, (select sum(value) as summe from percentile ) as foo
group by a.id, a.value, foo.summe order by id;
 id | value | numeric
----+-------+---------
  1 |    10 |    9.00
  2 |    20 |   18.00
  3 |    30 |   27.00
  4 |    50 |   45.00
(4 rows)


HTH, Andreas
--
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net

pgsql-general by date:

Previous
From: "Albe Laurenz"
Date:
Subject: Re: Postgres Security Checklist
Next
From: Abdul Rehman
Date:
Subject: Number Conversion Function