pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Re: Aggregates not allowed in WHERE clause?
5+ messages / 4 participants
[nested] [flat]

* Aggregates not allowed in WHERE clause?
@ 2002-06-19 08:04 Joachim Trinkwitz <jtr@uni-bonn.de>
  1970-01-01 00:00 ` Re: Aggregates not allowed in WHERE clause? Christoph Haller <ch@rodos.fzk.de>
  2002-06-19 08:13 ` Re: Aggregates not allowed in WHERE clause? Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  2002-06-19 08:18 ` Re: Aggregates not allowed in WHERE clause? Achilleus Mantzios <achill@matrix.gatewaynet.com>
  0 siblings, 3 replies; 5+ messages in thread

From: Joachim Trinkwitz @ 2002-06-19 08:04 UTC (permalink / raw)
  To: pgsql-sql

Hi all,

I have a table (lv) with a field "semester" and I'm trying to fish out all
rows which have a value corresponding to a max() value of another
table's (lf_sem) "semester" field. The intention is to keep a value
with the current term in lf_sem so I can get all rows which concern
this term.

Example tables:

lv
==
semester | kvvnr
---------+------
2001ss   | 4185
2001ss   | 4203
2002ws   | 4163
2002ws   | 4190

lf_sem
======
semester
--------
2001ws
2002ss
2002ws

At first I tried this query:

  SELECT kvvnr
  FROM lv, lf_sem
  WHERE lv.semester = max(lf_sem.semester);

This yields the message: 'Aggregates not allowed in WHERE clause'.

Next I tried this one:

  SELECT kvvnr, max(lf_sem.semester) AS akt_semester
  FROM lv, lf_sem
  WHERE lv.semester = akt_semester;

Now I got: 'Attribute 'akt_semester' not found'

Is there another way to get what I want?

Clueless,
joachim



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Aggregates not allowed in WHERE clause?
  2002-06-19 08:04 Aggregates not allowed in WHERE clause? Joachim Trinkwitz <jtr@uni-bonn.de>
@ 1970-01-01 00:00 ` Christoph Haller <ch@rodos.fzk.de>
  2002-06-20 08:05   ` Re: Aggregates not allowed in WHERE clause? Joachim Trinkwitz <jtr@uni-bonn.de>
  2 siblings, 1 reply; 5+ messages in thread

From: Christoph Haller @ 1970-01-01 00:00 UTC (permalink / raw)
  To: jtr@uni-bonn.de; +Cc: pgsql-sql

Joachim, 
Try 

SELECT kvvnr, semester FROM lv 
WHERE semester = (SELECT MAX(semester) FROM lf_sem) ; 

Are you sure the MAX function will work on your 
text resp. char/varchar attribute 'semester'? 

Regards, Christoph 




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Aggregates not allowed in WHERE clause?
  2002-06-19 08:04 Aggregates not allowed in WHERE clause? Joachim Trinkwitz <jtr@uni-bonn.de>
  1970-01-01 00:00 ` Re: Aggregates not allowed in WHERE clause? Christoph Haller <ch@rodos.fzk.de>
@ 2002-06-20 08:05   ` Joachim Trinkwitz <jtr@uni-bonn.de>
  0 siblings, 0 replies; 5+ messages in thread

From: Joachim Trinkwitz @ 2002-06-20 08:05 UTC (permalink / raw)
  To: pgsql-sql

Thanks for all your answers, it is working now.

Christoph Haller <ch@rodos.fzk.de> writes:

> Are you sure the MAX function will work on your 
> text resp. char/varchar attribute 'semester'? 

Yes, this works, I think because the ASCII (or whatever) value of 's'
is lower than that of 'w'.

Greetings,
joachim



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Aggregates not allowed in WHERE clause?
  2002-06-19 08:04 Aggregates not allowed in WHERE clause? Joachim Trinkwitz <jtr@uni-bonn.de>
@ 2002-06-19 08:13 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  2 siblings, 0 replies; 5+ messages in thread

From: Christopher Kings-Lynne @ 2002-06-19 08:13 UTC (permalink / raw)
  To: Joachim Trinkwitz <jtr@uni-bonn.de>; pgsql-sql

> Next I tried this one:
> 
>   SELECT kvvnr, max(lf_sem.semester) AS akt_semester
>   FROM lv, lf_sem
>   WHERE lv.semester = akt_semester;
> 
> Now I got: 'Attribute 'akt_semester' not found'
> 
> Is there another way to get what I want?

What about:

SELECT kvvnr FROM lv WHERE semester = (SELECT MAX(semester) FROM lf_sem);

Chris




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Aggregates not allowed in WHERE clause?
  2002-06-19 08:04 Aggregates not allowed in WHERE clause? Joachim Trinkwitz <jtr@uni-bonn.de>
@ 2002-06-19 08:18 ` Achilleus Mantzios <achill@matrix.gatewaynet.com>
  2 siblings, 0 replies; 5+ messages in thread

From: Achilleus Mantzios @ 2002-06-19 08:18 UTC (permalink / raw)
  To: Joachim Trinkwitz <jtr@uni-bonn.de>; +Cc: pgsql-sql

On 19 Jun 2002, Joachim Trinkwitz wrote:

> Hi all,
> 
> I have a table (lv) with a field "semester" and I'm trying to fish out all
> rows which have a value corresponding to a max() value of another
> table's (lf_sem) "semester" field. The intention is to keep a value
> with the current term in lf_sem so I can get all rows which concern
> this term.
> 
> Example tables:
> 
> lv
> ==
> semester | kvvnr
> ---------+------
> 2001ss   | 4185
> 2001ss   | 4203
> 2002ws   | 4163
> 2002ws   | 4190
> 
> lf_sem
> ======
> semester
> --------
> 2001ws
> 2002ss
> 2002ws
> 
> At first I tried this query:
> 
>   SELECT kvvnr
>   FROM lv, lf_sem
>   WHERE lv.semester = max(lf_sem.semester);
> 
> This yields the message: 'Aggregates not allowed in WHERE clause'.
> 
> Next I tried this one:
> 
>   SELECT kvvnr, max(lf_sem.semester) AS akt_semester
>   FROM lv, lf_sem
>   WHERE lv.semester = akt_semester;
> 
> Now I got: 'Attribute 'akt_semester' not found'
> 
> Is there another way to get what I want?

SELECT lv.kvvnr,lv.semester from lv where lv.semester = (select 
max(semester) from lf_sem); 

> 
> Clueless,
> joachim
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
> 

-- 
Achilleus Mantzios
S/W Engineer
IT dept
Dynacom Tankers Mngmt
tel:    +30-10-8981112
fax:    +30-10-8981877
email:  achill@matrix.gatewaynet.com
        mantzios@softlab.ece.ntua.gr




^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2002-06-20 08:05 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-06-19 08:04 Aggregates not allowed in WHERE clause? Joachim Trinkwitz <jtr@uni-bonn.de>
1970-01-01 00:00 ` Christoph Haller <ch@rodos.fzk.de>
2002-06-20 08:05   ` Joachim Trinkwitz <jtr@uni-bonn.de>
2002-06-19 08:13 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
2002-06-19 08:18 ` Achilleus Mantzios <achill@matrix.gatewaynet.com>

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