Re: sub-select with aggregate

From: Tomasz Myrta <jasiek(at)klaster(dot)net>
To: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: sub-select with aggregate
Date: 2002-10-23 14:02:58
Message-ID: 3DB6AC12.3030506@klaster.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Uz.ytkownik Stephan Szabo napisa?:
> Does using X.group_id=3 in the where clause work better?
It works better, but not if you want to create a view and make
"select * from some_view where group_id=3" :-(
>
> On 7.3 with no statistics for the table, that appears
> to move the filter into the subquery plan rather than the
> outer users scan.
Do you mean the second query will work on 7.3?
select
group_id,
user_id,
a/sum_a as percent_a,
b/sum_b as percent_b
from
users U,
(select
sum(a) as sum_a,
sum(b) as sum_b
from users where group_id=U.group_id) X
where group_id=3;

Tomasz Myrta

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Carlos Sousa 2002-10-23 14:05:50 problem with a query
Previous Message Tomasz Myrta 2002-10-23 13:52:56 Re: 7.2 time format funtion issue