X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 35862476362 for ; Tue, 15 Apr 2003 15:42:56 -0400 (EDT) Received: from rtlocal.trade-india.com (mail-relay.trade-india.com [203.196.129.235]) by postgresql.org (Postfix) with SMTP id 192804763BD for ; Tue, 15 Apr 2003 15:42:08 -0400 (EDT) Received: (qmail 3587 invoked from network); 15 Apr 2003 19:44:26 -0000 Received: from ns1.trade-india.com (HELO www.trade-india.com) (66.234.10.14) by infocom-236-129-del.trade-india.com with SMTP; 15 Apr 2003 19:44:26 -0000 Received: (qmail 14586 invoked by uid 99); 15 Apr 2003 19:41:08 -0000 Received: from 219.65.253.230 (SquirrelMail authenticated user mallah) by mail.trade-india.com with HTTP; Wed, 16 Apr 2003 01:11:08 +0530 (IST) Message-ID: <1608.219.65.253.230.1050435668.squirrel@mail.trade-india.com> Date: Wed, 16 Apr 2003 01:11:08 +0530 (IST) Subject: Re: Percentage of Total Occurances From: To: In-Reply-To: <30270000.1050433172@saturn> References: <6790000.1050418432@saturn> <1177.219.65.253.230.1050426637.squirrel@mail.trade-india.com> <30270000.1050433172@saturn> X-Priority: 3 Importance: Normal X-MSMail-Priority: Normal Cc: X-Mailer: SquirrelMail (version 1.2.6) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, hits=-23.6 required=5.0 tests=BAYES_01,IN_REP_TO,MISSING_MIMEOLE,MISSING_OUTLOOK_NAME, NO_DNS_FOR_FROM,NO_REAL_NAME,QUOTED_EMAIL_TEXT,REFERENCES, REPLY_WITH_QUOTES autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/240 X-Sequence-Number: 12941 well if everything in a single query is that imp u may do this subselect: select answer_id , 1.0*count(*) / (select count(*) from polls where poll_= id =3D ?) from polls where poll_id =3D ? group by answer_id ; and if u need to trim the trailing digits after decimal do to_char(value , '99.99') since u have not provided any sample data i cann't test it. > On 04/15/03 22:40:37 +0530 mallah@trade-india.com wrote: > >>> I have a table being used for poll results: >>> >>> id >>> poll_id >>> question_id >>> answer_id >>> datestamp >>> >>> I what to figure out the percentage or respondants that gave each answe= r. This is based on >>> occurance rather than values. >> >> select answer_id , 1.0*count(*) / (select count(*) from polls where p= oll_id =3D ?) from polls where poll_id =3D ? group by answer_id ; >> >> gives number of response of each answer >> >> total_response =3D select count(*) from polls where poll_id =3D ? >> >> getting %age shud be trivial. >> >> Dunno if i missed your question . > > I'm looking to do everything in a single query. > > And get something like: > > answer_id -> percentage > > Thanks, > > A. > > -- > Adam Sherman > Tritus CG Inc. > http://www.tritus.ca/ > +1 (613) 797-6819 > > > ---------------------------(end of broadcast)--------------------------- = TIP 5: Have you > checked our extensive FAQ? > > http://www.postgresql.org/docs/faqs/FAQ.html ----------------------------------------- Get your free web based email at trade-india.com. "India's Leading B2B eMarketplace.!" http://www.trade-india.com/