Re: [SQL] calculating percentages - Mailing list pgsql-sql

From Tiberiu Craciun
Subject Re: [SQL] calculating percentages
Date
Msg-id 00e901becc76$521ea5a0$0201a8c0@tibi.akela.ro
Whole thread Raw
List pgsql-sql
There is an example :

create table values ( value float ) ;
create function sum_val() returns float as '
    select sum(value) as return from values;
' language 'sql';
..........
select (value/sum_val())*100 as percent from values;

if value is integer than

create table values ( value int2 ) ;
create function sum_val() returns int2 as '
    select sum(value) as return from values;
' language 'sql';
..........
select (value::float/sum_val()::float)*100 as percent from values;


-----Original Message-----
From: Thomas Good <tomg@admin.nrnet.org>
To: PostgreSQL::SQL List <pgsql-sql@postgreSQL.org>
Date: lundi 12 juillet 1999 22:31
Subject: [SQL] calculating percentages


>Hi.
>
>I am trying to do outcome studies on pt before and after treatment
>recidivism rates...and having some trouble calculating percentages.
>
>How does one do this:   SELECT (current_value/target) * 100;
>in postgres? 
>
>Cheers - and thanks,
>Tom
>
>------- North Richmond Community Mental Health Center -------
>
>Thomas Good                                   MIS Coordinator
>Vital Signs:                  tomg@ { admin | q8 } .nrnet.org
>                                          Phone: 718-354-5528 
>                                          Fax:   718-354-5056 
>                             
>/* Member: Computer Professionals For Social Responsibility */
>
>
>

pgsql-sql by date:

Previous
From: Thomas Good
Date:
Subject: calculating percentages
Next
From: Tom Lane
Date:
Subject: Re: [SQL] Stupid question about default time value