Re: user defined aggregate for percentile calculations

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: user defined aggregate for percentile calculations
Date: 2009-04-06 08:53:28
Message-ID: 20090406085328.GA8320@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Abdul Rehman 2009-04-06 10:22:56 Number Conversion Function
Previous Message Albe Laurenz 2009-04-06 08:08:12 Re: Postgres Security Checklist