Re: Correlated Subquery and calculated column non-functional

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: The Frog <mr(dot)frog(dot)to(dot)you(at)googlemail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Correlated Subquery and calculated column non-functional
Date: 2009-10-30 17:42:56
Message-ID: 4AEB25A0.30407@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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.

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod(at)iol(dot)ie

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Broersma 2009-10-30 17:46:35 Re: Correlated Subquery and calculated column non-functional
Previous Message silly8888 2009-10-30 17:03:39 Re: CREATE TABLE LIKE and SERIAL