Re: [GENERAL] Calcuate percentage.

1999-03-10 Thread Kaare Rasmussen
> P.S. In oracle, I'd use a sub-query: > > SELECT var, COUNT(*) / total_count > FROM temp, >( SELECT COUNT(*) AS total_count >FROM temp >) > GROUP BY var; I thought that subqueries were allowed in PostgreSQL after 6.2?

Re: [GENERAL] Calcuate percentage.

1999-03-09 Thread Clark Evans
It's crude and not very efficient, but here is a solution: CREATE TABLE temp ( var INT2 ); INSERT INTO temp VALUES (1); etc. CREATE FUNCTION temp_row_count() RETURNS FLOAT AS 'SELECT COUNT(*)::FLOAT AS result FROM temp' LANGUAGE 'sql'; SELECT var, COUNT(*)::FLOAT / temp_row_count() AS pct FROM

Re: [GENERAL] Calcuate percentage.

1999-03-09 Thread Kaare Rasmussen
> Can I somehow get the total number of rows in > a function? create function numRows() returns int4 as 'select count(*) from ' language 'sql'; > select var1, count(*) / numRows() * 100 from table1 group by var1; maybe this is better select var1, (count(*) * 100) / numRows() from tab

Re: [GENERAL] Calcuate percentage.

1999-03-09 Thread Sze Yuen Wong
select count(*) into t2 from stations; FATAL 1: btree: failed to add item to the right sibling Any clue? ---Marcin Grondecki wrote: > > select count (*) into t1 from t; > select count(varl), varl into t2 from t group by varl; > select varl, (t2.count*100/t1.count) from t2, t1; > > and,

Re: [GENERAL] Calcuate percentage.

1999-03-09 Thread Marcin Grondecki
select count (*) into t1 from t; select count(varl), varl into t2 from t group by varl; select varl, (t2.count*100/t1.count) from t2, t1; and, of coz, drop tables t1 'n' t2 ;) (i don't know it's my laminess, but syntax "select ... into TEMP ddd ... does'n work for me - maybe suggestions? a bug i

Re: [GENERAL] Calcuate percentage.

1999-03-09 Thread Sze Yuen Wong
Can I somehow get the total number of rows in a function? if so, then I can say: select var1, count(*) / numRows() * 100 from table1 group by var1; Sze Wong ---"K.T." wrote: > > select var1, count(*) from table1 group by var1; > > will get you the count of how many of each number there is.

Re: [GENERAL] Calcuate percentage.

1999-03-09 Thread Sze Yuen Wong
> > select var1, count(*) from table1 group by var1; > > will get you the count of how many of each number there is... > > I think the only way is to get the max and manually loop thru the rows and > calc the percentage. ==>You mean externally using a programming ==>language ==>to do it? >

Re: [GENERAL] Calcuate percentage.

1999-03-09 Thread K.T.
select var1, count(*) from table1 group by var1; will get you the count of how many of each number there is... I think the only way is to get the max and manually loop thru the rows and calc the percentage. -Original Message- From: Sze Yuen Wong <[EMAIL PROTECTED]> To: [EMAIL PROTECTED]