Re: [GENERAL] Calcuate percentage.

From: Kaare Rasmussen <kar(at)webline(dot)dk>
To: pgsql-general(at)hub(dot)org
Subject: Re: [GENERAL] Calcuate percentage.
Date: 1999-03-09 20:42:33
Message-ID: 199903092042.VAA03399@bohr.webline.dk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> Can I somehow get the total number of rows in
> a function?

create function numRows() returns int4
as 'select count(*) from <table>'
language 'sql';

> select var1, count(*) / numRows() * 100 from table1 group by var1;

maybe this is better

select var1, (count(*) * 100) / numRows() from table1 group by var1;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Kaare Rasmussen 1999-03-09 20:47:42 Table as parameter in function
Previous Message Brett W. McCoy 1999-03-09 20:29:11 Re: [GENERAL] i want to start automaticly postgres when a reboot my server...help please.....