Re: A subselect in an aggregate

From: Ed Loehr <eloehr(at)austin(dot)rr(dot)com>
To: Bryan White <bryan(at)arcamax(dot)com>
Cc: pgsql-sql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: A subselect in an aggregate
Date: 2000-06-26 16:57:05
Message-ID: 39578B61.CDAF7D91@austin.rr.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Bryan White wrote:
>
> This statement works:
> select date, (select sum(qty * price) from orderdetail d where d.orderid =
> orders.orderid) from orders
>
> But when I try to do something like this:
>
> select date, sum(select sum(qty * price) from orderdetail d where d.orderid
> = orders.orderid) from orders group by date
>
> I get ERROR: parser: parse error at or near "select"
>
> Is there a way to apply an agregate function to a subselect like this?

Avoiding the question, I'm wondering if this simpler form wouldn't be
what you're after?

select o.date, sum(d.qty * d.price)
from orderdetail d, orders o
where d.orderid = o.orderid
group by o.date

Regards,
Ed Loehr

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Graham Vickrage 2000-06-26 17:00:31 pg_dump problem
Previous Message Bryan White 2000-06-26 16:36:31 A subselect in an aggregate