Correlated Subquery and calculated column non-functional

Поиск
Список
Период
Сортировка
От The Frog
Тема Correlated Subquery and calculated column non-functional
Дата
Msg-id 895cd21c-e483-4764-b47e-217d5a841e6f@37g2000yqm.googlegroups.com
обсуждение исходный текст
Ответы Re: Correlated Subquery and calculated column non-functional  (Raymond O'Donnell <rod@iol.ie>)
Re: Correlated Subquery and calculated column non-functional  (Thomas Kellerer <spam_eater@gmx.net>)
Список 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 по дате отправления:

Предыдущее
От: silly8888
Дата:
Сообщение: Re: CREATE TABLE LIKE and SERIAL
Следующее
От: Raymond O'Donnell
Дата:
Сообщение: Re: Correlated Subquery and calculated column non-functional