Correlated Subquery and calculated column non-functional

From: The Frog <mr(dot)frog(dot)to(dot)you(at)googlemail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Correlated Subquery and calculated column non-functional
Date: 2009-10-30 10:07:36
Message-ID: 895cd21c-e483-4764-b47e-217d5a841e6f@37g2000yqm.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Everyone,

I am having an issue with a query that I thought would be a fairly
simple matter to implement, but apparently I have done something
wrong. Can anyone point me in the right direction for a solution and
explain where I have made my mistake? The idea is to produce a rank
value for each row in the resultset.

This is the query:

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
from
cube_sales.sales INNER JOIN
cube_sales.product ON
sales.productid = product.productid
group by
product.manufacturer,
product.brand;

I am receiving a : column "turnover" does not exist
SQL state: 42703
Character: 155

I understand that there is some difference with subselects in Postgres
vs MySQL or Oracle for example, but I am out of my depth on this one.

Can anyone help?

The Frog

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Steve Clark 2009-10-30 11:15:47 Re: checkpoints/bgwriter tuning verification
Previous Message Thom Brown 2009-10-30 09:16:58 Re: Forms generator ?