select distinct on

Поиск
Список
Период
Сортировка
От Dave Ahn
Тема select distinct on
Дата
Msg-id 20001120171615.A417229@cecum.vec.wfubmc.edu
обсуждение исходный текст
Ответы Re: select distinct on  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
Hello,

I am trying to use SELECT DISTINCT ON.  This works as intended:
    SELECT DISTINCT ON (f1) * from table ORDER BY f1

 f1 | f2 | f3
----+----+----
  1 |  2 |  3
  2 |  2 |  2
  3 |  1 |  2

However, I am trying to order the results by non-distinct fields f2, f3
to get:

 f1 | f2 | f3
----+----+----
  3 |  1 |  2
  2 |  2 |  2
  1 |  2 |  3

Clearly this does not work:
    SELECT DISTINCT ON (f1) * from table ORDER BY f2, f3, f1

So is there some other way without SELECT INTO a temporary table?
Thanks in advance.
Dave
--
Dave Ahn | ahn@vec.wfubmc.edu | Wake Forest University Baptist Medical Center

When you were born, you cried and the world rejoiced.  Try to live your life
so that when you die, you will rejoice and the world will cry.  -1/2 jj^2

В списке pgsql-general по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: posible documentation error.
Следующее
От: "Willis, Ian (Ento, Canberra)"
Дата:
Сообщение: RE: External Large objects what became of them