Re: create aggregate function 'count_bool( column_name, boolean )' - Mailing list pgsql-sql

From Richard Broersma Jr
Subject Re: create aggregate function 'count_bool( column_name, boolean )'
Date
Msg-id 20060707155924.93209.qmail@web31806.mail.mud.yahoo.com
Whole thread Raw
In response to create aggregate function 'count_bool( column_name, boolean )'  ("James Moliere" <jmoliere@ucsd.edu>)
List 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
andA1.product_id=A3.product_id   ) as TS
 
from some_table as A1
group by product_id;

Regards,

Richard Broersma Jr.





pgsql-sql by date:

Previous
From: "Rodrigo De Leon"
Date:
Subject: Re: SELECT substring with regex
Next
From: Gary Stainburn
Date:
Subject: Re: SELECT substring with regex