Skip site navigation (1) Skip section navigation (2)


From: "Costin Manda" <costin(at)interpoint(dot)ro>
To: "pgsql" <pgsql-novice(at)postgresql(dot)org>
Subject: sql
Date: 2004-06-25 11:40:16
Message-ID: 009c01c45aa9$2fde7ee0$96b0e6c1@Costin (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
Actually, it can be done with a temporary table, as I have already told
Cristi (short for Cristian, btw :) ) like this:

SELECT m1, max (ore) AS mx, sum(ore) AS sm INTO TEMPORARY tmp FROM xxx GROUP
BY m1;
SELECT co,co1,n1,l1,tmp.m1,sm FROM xxx JOIN tmp ON xxx.m1=tmp.m1 AND ORDER BY tmp.m1 asc;

Ain't I a stinker? :)

I have to ask you guys if you know if this way is faster than making a
script that computes the max and the sum while parsing the table. Because
that join could slow things down, I guess...

The reason for this post (besides that of bragging) is that people bump into
similar problems all the time.
Like finding the values in the row that has one value maximum. You can't do
"select a,b,c,d from table where d=max(d) group by c";
The above example is my solution to it. I invite you to find other
solutions, maybe more ellegant.


In response to

  • Re: sql at 2004-06-24 18:20:43 from Manfred Koizar

pgsql-novice by date

Next:From: Andrew HammondDate: 2004-06-25 15:37:52
Subject: Re: sql
Previous:From: A PalmbladDate: 2004-06-24 20:10:46
Subject: Re: database corruption

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group