sql

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
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
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
xxx.ore=tmp.mx 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.

Siderite

In response to

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

Browse pgsql-novice by date

  From Date Subject
Next Message Andrew Hammond 2004-06-25 15:37:52 Re: sql
Previous Message A Palmblad 2004-06-24 20:10:46 Re: database corruption