master/detail

Поиск
Список
Период
Сортировка
От Jan Bakuwel
Тема master/detail
Дата
Msg-id 4FB97B70.6080604@greenpeace.org
обсуждение исходный текст
Ответ на Re: Need help in grouping records  (Andreas <maps.on@gmx.net>)
Ответы Re: master/detail  ("Raj Mathur (राज माथुर)" <raju@linux-delhi.org>)
Re: master/detail  (Mario Dankoor <m.p.dankoor@gmail.com>)
Re: master/detail  (Andreas Kretschmer <andreas@a-kretschmer.de>)
Список pgsql-sql
Hi,

I'm trying to get my head around the following question. As an example
take a table with products:

productid (pk)
name

and productprice

productpriceid (pk)
productid (fk)
pricedate
price

There are multiple records in productprice for each product as prices
(often) go up and (less often) go down.

I'm looking for a query that returns the following:

productid, name, pricedate, current_price, difference

current_price is the latest (ie. most recent date) price of the product
and difference is the difference in price between the latest price and
the price before the latest.

Any suggestions how to do this with SQL only? I can make it work with a
function (probably less efficient) but think this should be possible
with SQL too...

cheers,
Jan



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

Предыдущее
От: Andreas
Дата:
Сообщение: Re: Need help in grouping records
Следующее
От: "Raj Mathur (राज माथुर)"
Дата:
Сообщение: Re: master/detail