Correlated Subquery and calculated column non-functional - Mailing list pgsql-general

From The Frog
Subject Correlated Subquery and calculated column non-functional
Date
Msg-id 895cd21c-e483-4764-b47e-217d5a841e6f@37g2000yqm.googlegroups.com
Whole thread Raw
Responses Re: Correlated Subquery and calculated column non-functional
Re: Correlated Subquery and calculated column non-functional
List 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

pgsql-general by date:

Previous
From: silly8888
Date:
Subject: Re: CREATE TABLE LIKE and SERIAL
Next
From: Raymond O'Donnell
Date:
Subject: Re: Correlated Subquery and calculated column non-functional