pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Haddon <tom@haddons.net>
To: pgsql-sql@postgresql.org
Subject: Sum of Every Column
Date: Wed, 23 Oct 2002 13:17:26 -0700 (PDT)
Message-ID: <31182.66.47.66.34.1035404246.squirrel@tomandshirl.com> (raw)

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






view thread (5+ messages)  latest in thread

Message-ID: <31182.66.47.66.34.1035404246.squirrel@tomandshirl.com>
Permalink:  ../31182.66.47.66.34.1035404246.squirrel@tomandshirl.com/
Also on:    postgresql.org/message-id/31182.66.47.66.34.1035404246.squirrel@tomandshirl.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tom@haddons.net
  Subject: Re: Sum of Every Column
  In-Reply-To: <31182.66.47.66.34.1035404246.squirrel@tomandshirl.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox