From: | Richard Broersma Jr <rabroersma(at)yahoo(dot)com> |
---|---|
To: | James Moliere <jmoliere(at)ucsd(dot)edu>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: create aggregate function 'count_bool( column_name, boolean )' |
Date: | 2006-07-07 15:59:24 |
Message-ID: | 20060707155924.93209.qmail@web31806.mail.mud.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
> 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.
From | Date | Subject | |
---|---|---|---|
Next Message | Scott Marlowe | 2006-07-07 16:47:00 | Re: Alternative to serial primary key |
Previous Message | Gary Stainburn | 2006-07-07 15:59:14 | Re: SELECT substring with regex |