Re: SQL query not working when GROUP BY / HAVING is used

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: SQL query not working when GROUP BY / HAVING is used
Дата
Msg-id Pine.BSF.4.21.0012190826240.76591-100000@megazone23.bigpanda.com
обсуждение исходный текст
Ответ на SQL query not working when GROUP BY / HAVING is used  (juerg.rietmann@pup.ch)
Список pgsql-sql
On Tue, 19 Dec 2000 juerg.rietmann@pup.ch wrote:

> Hello there
> 
> I have a question regarding a SQL statement.
> 
> When I execute (and that's what I need)
> 
> SELECT Zylinder.Z_durch_soll, Zylinder.Z_id, Zylinder.Z_durch_ist,
> ((Zylinder.Z_durch_soll+0.12) - Zylinder.Z_durch_ist) AS durchmesserdelta,
> (Zylinder.Z_durch_soll+0.12) AS effektiv
> FROM Auftrag,Zylinder_Typen, Zylinder
> WHERE Auftrag.A_nr = '11'
> AND (  Auftrag.A_farbe_1  > '0' AND Zylinder_Typen.Z_farbe='1' AND
> Zylinder_Typen.Z_SW='0')
> AND Zylinder_Typen.Z_durch_soll = Zylinder.Z_durch_soll
> AND Auftrag.A_Ztyp=Zylinder.Z_typ
> AND Z_A_nr = NULL
> AND Z_status = 'zcu'
> GROUP BY Zylinder.Z_durch_soll
> HAVING durchmesserdelta >= 0.085
> ORDER BY Zylinder_Typen.Z_durch_soll desc

This query is not legal SQL.  All columns in the select list of
a group by query must either be grouped columns or set value
functions (pretty much anyway).  The general construct is legal
but there are syntax rules for GROUP BY that you are violating.

If Z_id and Z_durch_ist are unique for values of Z_durch_soll
you might try grouping on all of them.  If not, the query above
is indeterminate since you are not specifying which Z_id and
which Z_durch_ist to use for a particular Z_durc_soll value.




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

Предыдущее
От: Alessio Bragadini
Дата:
Сообщение: Re: Bounds checking on an alias
Следующее
От: "Josh Berkus"
Дата:
Сообщение: Re: Tree structure table normalization problem (do I need a trigger?)