Re: SQL If-Then Logic in Query

Поиск
Список
Период
Сортировка
От Holger Klawitter
Тема Re: SQL If-Then Logic in Query
Дата
Msg-id 200207181505.34086.lists@klawitter.de
обсуждение исходный текст
Ответ на SQL If-Then Logic in Query  ("User" <User@Anonymous.USA>)
Список pgsql-general
Hi Mr. or Mrs. X,

I understand concerns regarding spam, but posts without a real name and
invalid return adresses are generally considered 'rude'. But I'll try to help
anyway :-)

Probably you will be fine using the distinct feature

SELECT
 DISTINCT ON (id)
 id,dept,perc
FROM
 your_table
ORDER BY
 id, perc desc, dept desc
;

You will receive only the first row with the given id. The sorting order
on perc and dept will make the row you need coming first.

> If this is not the correct group to post this question, sorry in advance.
> If you can point me to a web site that may have a tutorial with an example
> similar to this, I'd appreciate it...

DISTINCT is explained in the SELECT section of the Reference manual.

With kind regards / mit freundlichem Gruß
    Holger Klawitter
--
Holger Klawitter                          http://www.klawitter.de
lists@klawitter.de

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

Предыдущее
От: Bruno Wolff III
Дата:
Сообщение: Re: SQL If-Then Logic in Query
Следующее
От: Siva Kumar
Дата:
Сообщение: Too many clients to Postgresql server