Search Postgresql Archives

Re: user defined aggregate for percentile calculations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux