From: Peter Brawley Date: February 28 2007 3:53pm Subject: Re: How to get query result... List-Archive: http://lists.mysql.com/mysql/205285 Message-Id: <45E5A589.3090504@earthlink.net> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit >What I want is to get next result: >Col.B | Col.A | Desription not in result query >A | -8 | -10-(-2) >B | -2 | -3-(-1) You need an ordering key; otherwise order is indeterminate. Still, comparisons based on row sequence are often easier to code in the application. A SQL hack is possible, but it may not perform very well. If the ordering key is a column k which, following your example, takes the values 1,2,3,4, and if your table follows the pattern of your example, this query yields your desired result: SELECT t1.b, t1.a AS B, (SELECT t2.a FROM tbl AS t2 WHERE t2.k=(t1.k-1)) AS delta FROM tbl AS t1 WHERE MOD(t1.k,2)=0; If your MySQL version is pre-4.1, you could accomplish this with user variables, but it would be messier. PB ----- aljosa wrote: > I have table with next data: > Col.A | Col.B | Col.C > -10 | A | D > -2 | A | R > -3 | B | D > -1 | B | R > > What I want is to get next result: > Col.B | Col.A | Desription not in result query > A | -8 | -10-(-2) > B | -2 | -3-(-1) > > I am trying for several days without any progress. Can anybody halp me? > Actualy I Have a problem with result Col.A. > > Thanks > -- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.412 / Virus Database: 268.18.4/705 - Release Date: 2/27/2007