pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: juerg.rietmann@pup.ch
Cc: pgsql-sql@postgresql.org
Subject: Re: SQL query not working when GROUP BY / HAVING is used
Date: Tue, 19 Dec 2000 08:29:51 -0800 (PST)
Message-ID: <Pine.BSF.4.21.0012190826240.76591-100000@megazone23.bigpanda.com> (raw)
In-Reply-To: <OF208AB5D1.6DAC762C-ONC12569BA.00365A4B@pup.ch>

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.





view thread (4+ messages)  latest in thread

Message-ID: <Pine.BSF.4.21.0012190826240.76591-100000@megazone23.bigpanda.com>
Permalink:  ../Pine.BSF.4.21.0012190826240.76591-100000@megazone23.bigpanda.com/
Also on:    postgresql.org/message-id/Pine.BSF.4.21.0012190826240.76591-100000@megazone23.bigpanda.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: sszabo@megazone23.bigpanda.com, juerg.rietmann@pup.ch
  Subject: Re: SQL query not working when GROUP BY / HAVING is used
  In-Reply-To: <Pine.BSF.4.21.0012190826240.76591-100000@megazone23.bigpanda.com>
  References: <OF208AB5D1.6DAC762C-ONC12569BA.00365A4B@pup.ch> <Pine.BSF.4.21.0012190826240.76591-100000@megazone23.bigpanda.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox