Received: from druid.net (druid.net [216.126.72.98]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f1PNs2x48126 for ; Sun, 25 Feb 2001 18:54:02 -0500 (EST) (envelope-from darcy@druid.net) Received: by druid.net (Postfix, from userid 1000) id 2F8E81A62; Sun, 25 Feb 2001 18:54:03 -0500 (EST) Subject: Re: Fwd: Re: sum(bool)? In-Reply-To: <01022522262800.01616@txino.mikasa.eh> "from J.Fernando Moyano at Feb 25, 2001 10:26:28 pm" To: "J.Fernando Moyano" Date: Sun, 25 Feb 2001 18:54:03 -0500 (EST) Cc: PgSQL-SQL X-Mailer: ELM [version 2.4ME+ PL78 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII Message-Id: <20010225235403.2F8E81A62@druid.net> From: darcy@druid.net (D'Arcy J.M. Cain) X-Archive-Number: 200102/392 X-Sequence-Number: 1597 Thus spake J.Fernando Moyano > El Viernes 23 Febrero 2001 16:22, escribiste: > > i want to add up the "true" values of a comparison like > > > > sum(a>b) > > > > it just doesn't work like this > > > > any workaround? > > I did exactly the same thing two months ago .... > > I created this tiny function: > > CREATE FUNCTION bool2int(bool) RETURNS integer > AS 'select (case when $1=true then 1 else 0 end)' > LANGUAGE 'sql'; > > > You can do: sum(bool2int(a>b)) > > easy ??? ;-)) Almost as easy as "SELECT COUNT(*) FROM table WHERE a > b" -- D'Arcy J.M. Cain | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.