Re: selecting latest record

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема Re: selecting latest record
Дата
Msg-id 162867790909220256k3865e0dcr742163d7828573c8@mail.gmail.com
обсуждение исходный текст
Ответ на selecting latest record  (Louis-David Mitterrand <vindex+lists-pgsql-sql@apartia.org>)
Ответы Re: selecting latest record  (Louis-David Mitterrand <vindex+lists-pgsql-sql@apartia.org>)
Список pgsql-sql
Hello

2009/9/22 Louis-David Mitterrand <vindex+lists-pgsql-sql@apartia.org>:
> Hi,
>
> I have a simple table
>
> price(id_product, price, date)
>
> which records price changes for each id_product. Each time a price
> changes a new tuple is created.
>
> What is the best way to select only the latest price of each id_product?

there are more ways - depends on what you wont.

one way is

SELECT *  FROM price WHERE (id_product, date) = (SELECT id_product, max(date)
                  FROM price                                                             GROUP BY
 
id_product)

Regards
Pavel Stehule

>
> Thanks,
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>


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

Предыдущее
От: Louis-David Mitterrand
Дата:
Сообщение: selecting latest record
Следующее
От: Louis-David Mitterrand
Дата:
Сообщение: Re: selecting latest record