Re: count and group by question

From: "Dann Corbit" <DCorbit(at)connx(dot)com>
To: "Ryan Mahoney" <ryan(at)paymentalliance(dot)net>
Cc: "Hannu Krosing" <hannu(at)tm(dot)ee>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: count and group by question
Date: 2002-06-19 23:12:14
Message-ID: D90A5A6C612A39408103E6ECDD77B82920CFA9@voyager.corporate.connx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> -----Original Message-----
> From: Ryan Mahoney [mailto:ryan(at)paymentalliance(dot)net]
> Sent: Wednesday, June 19, 2002 4:00 PM
> To: Dann Corbit
> Cc: Hannu Krosing; pgsql-hackers(at)postgresql(dot)org
> Subject: Re: [HACKERS] count and group by question
>
>
> OK, so I tried both queries but they don't meet my
> requirement, I think
> I wasn't clear. The methods suggested both return the aggregate count
> as if the rows had not been grouped. What I am looking for is a count
> of how many rows were returned *with* the grouping.
>
> So, suppose there are 1000 orders total, but when grouped by
> product 200
> rows are returned. I am trying to find a way to get that 200 not the
> original 1000 count.
>
> Does this make sense? The Union was really interesting, I
> haven't used
> union very much - but I will now!

Warning -- totally untested and glommed from memory -- probably not
quite right...

SELECT count (distinct
cast(to_char(pa_shopping_cart.delivery_date, 'FMMM/FMDD/YY') as
varchar) || pa_products.product_name || pa_orders.order_state)
FROM
pa_shopping_cart,
pa_products,
pa_orders
WHERE
pa_shopping_cart.order_id = pa_orders.order_id AND
pa_shopping_cart.product_id = pa_products.product_id

Browse pgsql-hackers by date

  From Date Subject
Next Message Rod Taylor 2002-06-19 23:20:37 Re: count and group by question
Previous Message Ryan Mahoney 2002-06-19 23:00:25 Re: count and group by question