Fwd: Re: [SQL] sql basic question - Mailing list pgsql-general

From Andreas Kretschmer
Subject Fwd: Re: [SQL] sql basic question
Date
Msg-id 103480208.422835.1356696271425.JavaMail.open-xchange@ox.ims-firmen.de
Whole thread Raw
List pgsql-general
sorry, first answer not to the list ...

---------- Ursprüngliche Nachricht ----------
Von: Andreas Kretschmer <andreas@a-kretschmer.de>
An: Antonio Parrotta <antonioparrotta@gmail.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


pgsql-general by date:

Previous
From: Amit Kapila
Date:
Subject: Re: Cursor fetch Problem.
Next
From: Christian Hammers
Date:
Subject: Re: update from a csv file?