Re: Correlated Subquery and calculated column non-functional

From: Richard Broersma <richard(dot)broersma(at)gmail(dot)com>
To: rod(at)iol(dot)ie
Cc: The Frog <mr(dot)frog(dot)to(dot)you(at)googlemail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Correlated Subquery and calculated column non-functional
Date: 2009-10-30 17:46:35
Message-ID: 396486430910301046j63d2f002ka26d556006f8ea4@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Oct 30, 2009 at 10:42 AM, Raymond O'Donnell <rod(at)iol(dot)ie> wrote:
> On 30/10/2009 10:07, The Frog wrote:
>> select
>>       product.manufacturer,
>>       product.brand,
>>       SUM(sales.qtysold * sales.unitprice) as turnover,
>>       (select count(*) from cube_sales.sales as Q WHERE SUM(sales.qtysold *
>> sales.unitprice) > turnover) + 1 as rank
>
> You can't use the alias "turnover" in the calculation as you have - you
> need to use the full expression instead, or push the calculation into a
> subquery.
>
> BTW you're also missing a closing parenthesis from that calculation.

Also you can't use aggregate functions in the WHERE clause. You'll
need to push it down to the HAVING clause.

--
Regards,
Richard Broersma Jr.

Visit the Los Angeles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Kellerer 2009-10-30 17:47:08 Re: Correlated Subquery and calculated column non-functional
Previous Message Raymond O'Donnell 2009-10-30 17:42:56 Re: Correlated Subquery and calculated column non-functional