Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 6731647648D for ; Wed, 23 Oct 2002 17:12:41 -0400 (EDT) Received: from beamish.nsd.ca (unknown [205.150.156.194]) by postgresql.org (Postfix) with ESMTP id 5B25D476478 for ; Wed, 23 Oct 2002 17:12:40 -0400 (EDT) Received: (from smap@localhost) by beamish.nsd.ca (8.9.3/8.9.3) id RAA21746; Wed, 23 Oct 2002 17:12:36 -0400 X-Authentication-Warning: beamish.nsd.ca: smap set sender to using -f Received: from reddog.nsd.ca(192.168.101.30) by beamish.nsd.ca via smap (V2.1/2.1+anti-relay+anti-spam) id xma021744; Wed, 23 Oct 02 17:12:31 -0400 Received: from nsd.ca (jllachan-linux.nsd.ca [192.168.101.148]) by reddog.nsd.ca (8.8.7/8.8.7) with ESMTP id RAA19491; Wed, 23 Oct 2002 17:11:57 -0400 Message-ID: <3DB710DF.DE045069@nsd.ca> Date: Wed, 23 Oct 2002 17:13:03 -0400 From: Jean-Luc Lachance X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.4.9-31 i686) X-Accept-Language: en MIME-Version: 1.0 To: tom@haddons.net Cc: pgsql-sql@postgresql.org Subject: Re: Sum of Every Column References: <31182.66.47.66.34.1035404245.squirrel@tomandshirl.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200210/315 X-Sequence-Number: 10032 Tom, You can add sum( case when then 1 else 0 end) for each field that you need. JLL Tom Haddon wrote: > > Hi Folks, > > I'm hoping to put together a query that generates a report on a table with > a large number of boolean fields. This report has to be able to adapt to > the number of fields in the table. Essentially, I want it to provide the > sum of TRUE values for each field for a given subset of the table. I've > got the query that returns the subset of the table (this is based on a > relationship with another table): > > SELECT breast_cancer_resources.* > FROM breast_cancer_resources, agency_contact_info > WHERE breast_cancer_resources.id=agency_contact_info.id > AND agency_contact_info.guideregion=1 > AND agency_contact_info.list_online=TRUE > > But I'm not sure how to generate the sum for each column. Should I be > looking elsewhere than SQL to do this for me, such as php (this is for a > web-based report)? > > Thanks, Tom > > ---------------------------(end of broadcast)--------------------------- > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org