From: Richard Broersma Jr <rabroersma@yahoo.com>
To: James Moliere <jmoliere@ucsd.edu>
To: pgsql-sql@postgresql.org
Subject: Re: create aggregate function 'count_bool( column_name, boolean )'
Date: Fri, 7 Jul 2006 08:59:24 -0700 (PDT)
Message-ID: <20060707155924.93209.qmail@web31806.mail.mud.yahoo.com> (raw)
In-Reply-To: <005b01c6a1cc$c43de9b0$0302a8c0@intelesis.org>
> 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.
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: rabroersma@yahoo.com, jmoliere@ucsd.edu
Subject: Re: create aggregate function 'count_bool( column_name, boolean )'
In-Reply-To: <20060707155924.93209.qmail@web31806.mail.mud.yahoo.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