Fwd: Re: [SQL] sql basic question

From: Andreas Kretschmer <andreas(at)a-kretschmer(dot)de>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Fwd: Re: [SQL] sql basic question
Date: 2012-12-28 12:04:31
Message-ID: 103480208.422835.1356696271425.JavaMail.open-xchange@ox.ims-firmen.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

sorry, first answer not to the list ...

---------- Ursprüngliche Nachricht ----------
Von: Andreas Kretschmer <andreas(at)a-kretschmer(dot)de>
An: Antonio Parrotta <antonioparrotta(at)gmail(dot)com>
Datum: 28. Dezember 2012 um 13:00
Betreff: Re: [SQL] sql basic question
>
> 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=*# 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=*# select * from (select distinct on (side) label, id, distance, side from
foo order by side, distance) a union all (select distinct on (side) label, id,
distance, side from foo order by side, distance desc) order by side desc, 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

Browse pgsql-general by date

  From Date Subject
Next Message Christian Hammers 2012-12-28 12:17:42 Re: update from a csv file?
Previous Message Harry 2012-12-28 11:45:20 Re: Cursor fetch Problem.