Received: from oxmail.ox.ac.uk (oxmail1.ox.ac.uk [129.67.1.1]) by hub.org (8.9.3/8.9.3) with ESMTP id LAA47282 for ; Tue, 18 Apr 2000 11:32:55 -0400 (EDT) (envelope-from moray.mcconnachie@computing-services.oxford.ac.uk) Received: from ermine.ox.ac.uk ([163.1.2.13]) by oxmail.ox.ac.uk with esmtp (Exim 3.12 #3) id 12hZzd-0005F7-00; Tue, 18 Apr 2000 16:32:49 +0100 Received: from ermine.ox.ac.uk ([163.1.2.13] helo=moraypc ident=root) by ermine.ox.ac.uk with smtp (Exim 3.13 #1) id 12hZzf-0003Yi-00; Tue, 18 Apr 2000 16:32:51 +0100 Message-ID: <00e601bfa94b$29833810$760e01a3@oucs.ox.ac.uk> From: "Moray McConnachie" To: "Ed" , "pgsql sql" References: <001d01bfa942$13d93180$b48c29d1@citenet.net> Subject: Re: One query for two information... Date: Tue, 18 Apr 2000 16:31:27 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.00.2919.6700 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700 X-Archive-Number: 200004/185 create function boolint (bool) RETURNS int4 AS 'SELECT CASE WHEN $1=''false'' THEN 0 ELSE 1 END;' LANGUAGE 'sql'; SELECT SUM(boolint(fieldname)) FROM tablename; note double single quote in 2nd line. Yours, Moray ---------------------------------------------------------------- Moray.McConnachie@computing-services.oxford.ac.uk ----- Original Message ----- From: "Ed" To: "pgsql sql" Sent: Tuesday, April 18, 2000 3:26 PM Subject: [SQL] One query for two information... Hi, I have a table containing only a bool filed. I would like to know how many records there is an on many ar true. Is there something I could do to get both answer in only one query... like : select count(*), sum(bool_col) from tablename but there is no sum(bool) function that would add 1 if it's true and 0 if it's false... ;( Any idea? Frédéric Boucher dziablo@lords.com