X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 0340252891 for ; Mon, 6 Jun 2005 07:06:09 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 36153-06 for ; Mon, 6 Jun 2005 10:06:06 +0000 (GMT) Received: from mx-00.sil.at (mx-00.sil.at [62.116.68.196]) by svr1.postgresql.org (Postfix) with ESMTP id 7358952841 for ; Mon, 6 Jun 2005 07:06:03 -0300 (ADT) Received: (qmail-ldap/ctrl 71586 invoked from network); 6 Jun 2005 10:06:03 -0000 Received: from unknown (HELO io.sonorys.at) ([213.235.243.42]) (envelope-sender ) by mx-00.sil.at (qmail-ldap-1.03) with SMTP for ; 6 Jun 2005 10:06:03 -0000 Received: from neptun.sonorys.at (neptun.sonorys.at [172.24.1.17]) by io.sonorys.at (8.11.7+Sun/8.11.7) with ESMTP id j56A62G11293 for ; Mon, 6 Jun 2005 12:06:03 +0200 (MEST) Received: by neptun.sonorys.at with Internet Mail Service (5.5.2653.19) id ; Mon, 6 Jun 2005 12:06:02 +0200 Message-ID: From: =?ISO-8859-1?Q?K=D6PFERL_Robert?= To: pgsql-sql@postgresql.org Subject: Re: How do write a query... Date: Mon, 6 Jun 2005 12:06:01 +0200 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="ISO-8859-1" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200506/73 X-Sequence-Number: 21674 You could have a look at the OFFSET and LIMIT modifiers as for untested example select ((select max( "AValue") from table group by "Num") - "AValue") as difference from table order by "AValue" desc offset 1 this says: give me a inversed ordered AValue-list but ommitting the first (biggest) and subtract each from the biggest value of each group |-----Original Message----- |From: Alain Reymond [mailto:arwebmail@skynet.be] |Sent: Mittwoch, 01. Juni 2005 18:01 |To: pgsql-sql@postgresql.org |Subject: [SQL] How do write a query... | | |Hello, | |I have the following problem : | |I have a table like |Id Num Date AValue |1 10 01/01/2005 50 |2 10 31/05/2005 60 |3 25 02/02/2005 55 |4 25 15/03/2005 43 |5 25 28/05/2005 62 |etc.. | |Id is unique, Num is an identification number with duplicates possible, |date is a ... date and Avalue... a value! | |If we have |Id Num Date AValue |Id1 Num1 Date1 AValue1 |Id2 Num1 Date2 AValue2 | |The table is ordered on Num+Date. |What I would like to calculate is (AValue2-AValue1) for a given Num |(here num1). | |In this case, I would have to calculate |60-50 for Num 10 |and |43-55, 62-43 for Num 25. | |Do you have any idea if it can be done simply with a request... | |I thank you | |Regards. | |Alain Reymond | | | |---------------------------(end of |broadcast)--------------------------- |TIP 2: you can get off all lists at once with the unregister command | (send "unregister YourEmailAddressHere" to |majordomo@postgresql.org) |