X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 6B8179FA322 for ; Fri, 7 Jul 2006 12:59:59 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 70261-03 for ; Fri, 7 Jul 2006 12:59:56 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web31806.mail.mud.yahoo.com (web31806.mail.mud.yahoo.com [68.142.207.69]) by postgresql.org (Postfix) with SMTP id 0818D9FA0EC for ; Fri, 7 Jul 2006 12:59:55 -0300 (ADT) Received: (qmail 93211 invoked by uid 60001); 7 Jul 2006 15:59:24 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=DCB3jJVUc/rPOunvZTOXTad3o9r247gzqJnraOfgBqfz+ellYUt0E3JYkMg08um+qle779Brtb6NhK5EiL11B/+p3uyaW3dEZ4DKh1AbIfQjyxhhwdBKQcGrVJxRnUE3W7WrtMQEAOlHBI4DkXBEl1Iz35W2JiFIpu2RqYZVnOA= ; Message-ID: <20060707155924.93209.qmail@web31806.mail.mud.yahoo.com> Received: from [65.211.203.97] by web31806.mail.mud.yahoo.com via HTTP; Fri, 07 Jul 2006 08:59:24 PDT Date: Fri, 7 Jul 2006 08:59:24 -0700 (PDT) From: Richard Broersma Jr Subject: Re: create aggregate function 'count_bool( column_name, boolean )' To: James Moliere , pgsql-sql@postgresql.org In-Reply-To: <005b01c6a1cc$c43de9b0$0302a8c0@intelesis.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/104 X-Sequence-Number: 25678 > so now I can create the statement > select distict product_id, count_bool(purchased, true), > count_bool(was_selected, true) from some_table group by product_id; > > instead of breaking the query into 3 seperate queries > > select distict product_id from some_table; > select count(purchased) from product_id where purchased = true; > select count(was_selected) from some_table where was_selected = true; > Am I missing a detail with SQL based aggregate function development? > Any help would be appreciated. how about: select product_id, ( select count(purchased) from some_table as A2 where purchased=true and A1.product_id=A2.product_id ) as TP, ( select count(selected) from some_table as A3 where purchased=true and A1.product_id=A3.product_id ) as TS from some_table as A1 group by product_id; Regards, Richard Broersma Jr.