Re: problem with sql

Поиск
Список
Период
Сортировка
От Michael Glaesmann
Тема Re: problem with sql
Дата
Msg-id 3A8501C8-06DB-11D8-B941-0005029FC1A7@myrealbox.com
обсуждение исходный текст
Ответ на problem with sql  (Adaś <adamn@qwe.pl>)
Список pgsql-sql
Hi Adam,

On Monday, Oct 20, 2003, at 01:56 Asia/Tokyo, Adaś wrote:
> status. I made a query using LAST and GROUP BY to select last order
> for each customer and I wanted to use it in UPDATE query, but it seems
> to be impossible.

I don't believe PostgreSQL has a built-in function similar to MS
Access' LAST. Something like the following might work for you:

SELECT DISTINCT ON (client) client, order_number, order_date FROM
orders ORDER BY order_date desc

You might have to change the DISTINCT ON terms to match what you want.
Check the docs for usage of DISTINCT ON.

Also, I've heard it's quite easy to write a custom function to do what
you want using CREATE FUNCTION. Haven't done it myself.

Hope it helps.

Michael


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

Предыдущее
От: Joe Conway
Дата:
Сообщение: Re: Referring to derived column name in a RECORD
Следующее
От: "Julian North"
Дата:
Сообщение: Re: naming conventions constraint