Re: [SQL] calculating percentages

From: "Tiberiu Craciun" <tiberiu(at)akela(dot)ro>
To: <pgsql-sql(at)postgreSQL(dot)org>
Subject: Re: [SQL] calculating percentages
Date: 1999-07-12 14:53:36
Message-ID: 00e901becc76$521ea5a0$0201a8c0@tibi.akela.ro
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)admin(dot)nrnet(dot)org>
To: PostgreSQL::SQL List <pgsql-sql(at)postgreSQL(dot)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 */
>
>
>

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 1999-07-12 15:06:08 Re: [SQL] Stupid question about default time value
Previous Message Thomas Good 1999-07-12 14:50:27 Re: [SQL] calculating percentages