Re: How to use result column names in having cause

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: How to use result column names in having cause
Дата
Msg-id 20060331065235.M61282@megazone.bigpanda.com
обсуждение исходный текст
Ответ на Re: How to use result column names in having cause  ("Andrus" <eetasoft@online.ee>)
Список pgsql-general
On Fri, 31 Mar 2006, Andrus wrote:

> >> In real application I have long expression instead of 123 and do'nt want
> >>  repeat this expression in HAVING clause.
> >
> > You have to repeat the expression. "AS" changes the output name, it
> > can't be used either in the where clause or any other limiting factor
> > like 'having':
>
> Doc about HAVING condition says:
>
> Each column referenced in condition must unambiguously reference a grouping
> colum
>
> HAVING x> AVG(bar) unambiguously references to a grouping column x

IIRC technically the query is invalid, because group by isn't supposed to
run on the output of select entries (as I think is stated by "Each
<grouping column reference> shall unambiguously reference a column of the
table resulting from the <from clause>.") and I'd guess this is a side
effect of allowing group by to work on the table resulting from the select
list as well.

I think the SQL way of writing this is to use a subselect and do two
levels (ie, generate a subselect that gives the table you want to group
and use it in the from clause of the outer query that does the grouping).

В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: configure: error: file 'tclConfig.sh' is required for Tcl
Следующее
От: Robert Treat
Дата:
Сообщение: Re: [Slightly OT] data model books/resources?