Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Toarv-0000dm-P2 for pgsql-sql@arkaria.postgresql.org; Fri, 28 Dec 2012 14:25:03 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Toaru-0002LU-Ok for pgsql-sql@arkaria.postgresql.org; Fri, 28 Dec 2012 14:25:02 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Toart-0002LK-Fx for pgsql-sql@postgresql.org; Fri, 28 Dec 2012 14:25:01 +0000 Received: from mailout01.ims-firmen.de ([213.174.32.96]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Toarr-0007e1-Eh for pgsql-sql@postgresql.org; Fri, 28 Dec 2012 14:25:00 +0000 Received: from mailin01.ims-firmen.de ([192.168.1.141]) by mailout01.ims-firmen.de with esmtp (envelope-from ) id 1Toarq-0003ng-iX for pgsql-sql@postgresql.org; Fri, 28 Dec 2012 15:24:58 +0100 Received: from [213.174.32.191] (helo=oxweb01.ims-firmen.de) by mailin01.ims-firmen.de with esmtpsa (TLSv1:RC4-MD5:128) (envelope-from ) id 1Toarq-0001N3-2P for pgsql-sql@postgresql.org; Fri, 28 Dec 2012 15:24:58 +0100 Date: Fri, 28 Dec 2012 15:21:34 +0100 (CET) From: Andreas Kretschmer Reply-To: Andreas Kretschmer To: "pgsql-sql@postgresql.org" Message-ID: <853734478.423112.1356704494708.JavaMail.open-xchange@ox.ims-firmen.de> Subject: Fwd: Re: sql basic question MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Priority: 3 Importance: Medium X-Mailer: Open-Xchange Mailer v6.20.6-Rev4 X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org sorry, only a private replay and not to the list ---------- Urspr=C3=BCngliche Nachricht ---------- Von: Andreas Kretschmer An: Antonio Parrotta Datum: 28. Dezember 2012 um 15:19 Betreff: Re: [SQL] sql basic question Hi, your question was: "What I want to achieve is a result table with min and m= ax distance for each side". Okay, with SIDE in 0,1,-1,2,-2,3,-3 there are exactly 14 possible values for each SIDE and Min/Max. If this is wrong, describe your problem better. Antonio Parrotta hat am 28. Dezember 2012 um 15= :12 geschrieben: > Hi Andreas, Anton, > > I did some test and both queries didn't worked. Maybe I was not clear with > the example provided. > My table contains more than 160K records with SIDE 0, 1, -1, 2, -2, 3 and > -3. > Example provided is a very small subset. > > *Andrea's *query is failing because it is getting only distinct SIDEs. The > query returns just 14 rows. > > *Anton's *one because it is joining on distance so merges records without= a > relation (I have many rows with a distance of 0 for example). I need to > have a join on IDs instead > > Thanks > > - Antonio > > > On 28 December 2012 13:00, Andreas Kretschmer wr= ote: > > > > > > > so the result should be: > > > LABEL ID Distance SIDE > > > "15"; 119006; 0.10975569030617; 1 > > > "19"; 64056; 0.41205442839764; 1 > > > "14"; 64054; 0.118448307450912; 0 > > > "24"; 119007; 0.59758734628752; 0 > > > > > > > > > > > > > > test=3D*# select * from foo; > > label | id | distance | side > > -------+--------+-------------------+------ > > 15 | 119006 | 0.10975569030617 | 1 > > 14 | 64054 | 0.118448307450912 | 0 > > 16 | 64055 | 0.176240407317772 | 0 > > 20 | 64057 | 0.39363711745035 | 0 > > 19 | 64056 | 0.41205442839764 | 1 > > 24 | 119007 | 0.59758734628752 | 0 > > (6 rows) > > > > test=3D*# select * from (select distinct on (side) label, id, distance,= side > > from > > foo order by side, distance) a union all (select distinct on (side) lab= el, > > id, > > distance, side from foo order by side, distance desc) order by side des= c, > > label; > > label | id | distance | side > > -------+--------+-------------------+------ > > 15 | 119006 | 0.10975569030617 | 1 > > 19 | 64056 | 0.41205442839764 | 1 > > 14 | 64054 | 0.118448307450912 | 0 > > 24 | 119007 | 0.59758734628752 | 0 > > (4 rows) > > > > > > HTH, Andreas > > > Hi Andreas, Anton, > > I did some test and both queries didn't worked. Maybe I was not clear wit= h the > example provided. > My table contains more than 160K records with SIDE 0, 1, -1, 2, -2, 3 and= -3. > Example provided is a very small subset. > > Andrea's query is failing because it is getting only distinct SIDEs. The = query > returns just 14 rows. > > Anton's one because it is joining on distance so merges records without a > relation (I have many rows with a distance of 0 for example). I need to h= ave a > join on IDs instead > > Thanks > > - Antonio > > > On 28 December 2012 13:00, Andreas Kretschmer w= rote: > > > > > > so the result should be: > > > LABEL ID Distance SIDE > > > "15"; 119006; 0.10975569030617; 1 > > > "19"; 64056; 0.41205442839764; 1 > > > "14"; 64054; 0.118448307450912; 0 > > > "24"; 119007; 0.59758734628752; 0 > > > > > > > > > > > > > > test=3D*# select * from foo; > > label | id | distance | side > > -------+--------+-------------------+------ > > 15 | 119006 | 0.10975569030617 | 1 > > 14 | 64054 | 0.118448307450912 | 0 > > 16 | 64055 | 0.176240407317772 | 0 > > 20 | 64057 | 0.39363711745035 | 0 > > 19 | 64056 | 0.41205442839764 | 1 > > 24 | 119007 | 0.59758734628752 | 0 > > (6 rows) > > > > test=3D*# select * from (select distinct on (side) label, id, distanc= e, side > > from > > foo order by side, distance) a union all (select distinct on (side) l= abel, > > id, > > distance, side from foo order by side, distance desc) order by side d= esc, > > label; > > label | id | distance | side > > -------+--------+-------------------+------ > > 15 | 119006 | 0.10975569030617 | 1 > > 19 | 64056 | 0.41205442839764 | 1 > > 14 | 64054 | 0.118448307450912 | 0 > > 24 | 119007 | 0.59758734628752 | 0 > > (4 rows) > > > > > > HTH, Andreas --=20 Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql