sql
От | Costin Manda |
---|---|
Тема | sql |
Дата | |
Msg-id | 009c01c45aa9$2fde7ee0$96b0e6c1@Costin обсуждение исходный текст |
Ответ на | sql ("cristi" <cristi@dmhi.ct.ro>) |
Список | 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
В списке pgsql-novice по дате отправления: