Re: [GENERAL] Calcuate percentage. - Mailing list pgsql-general

From Kaare Rasmussen
Subject Re: [GENERAL] Calcuate percentage.
Date
Msg-id 199903092042.VAA03399@bohr.webline.dk
Whole thread Raw
In response to Re: [GENERAL] Calcuate percentage.  (Sze Yuen Wong <swong_@yahoo.com>)
List 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;


pgsql-general by date:

Previous
From: Kaare Rasmussen
Date:
Subject: Table as parameter in function
Next
From: Clark Evans
Date:
Subject: Re: [GENERAL] Calcuate percentage.