Received: from ns.canad.ro (IDENT:root@ns.canad.ro [193.230.177.1]) by hub.org (8.9.3/8.9.3) with ESMTP id KAA90587 for ; Mon, 12 Jul 1999 10:55:53 -0400 (EDT) (envelope-from tiberiu@akela.ro) Received: from linux.akela.ro (root@ns.akela.ro [193.226.47.105]) by ns.canad.ro (8.9.3/8.9.3) with ESMTP id RAA11186 for ; Mon, 12 Jul 1999 17:53:43 +0300 Received: from tibi (tibi.akela.ro [192.168.1.2]) by linux.akela.ro (8.9.1/8.9.1) with SMTP id RAA15860 for ; Mon, 12 Jul 1999 17:55:27 -0200 Message-ID: <00e901becc76$521ea5a0$0201a8c0@tibi.akela.ro> From: "Tiberiu Craciun" To: Subject: Re: [SQL] calculating percentages Date: Mon, 12 Jul 1999 17:53:36 +0300 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_00E6_01BECC8F.774A4BE0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 4.72.3110.5 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 This is a multi-part message in MIME format. ------=_NextPart_000_00E6_01BECC8F.774A4BE0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable 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 To: PostgreSQL::SQL List 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? =20 > >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 =20 > Fax: 718-354-5056 =20 > =20 >/* Member: Computer Professionals For Social Responsibility */=20 > > > ------=_NextPart_000_00E6_01BECC8F.774A4BE0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
There is an example :

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

if value is integer = than

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


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


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