pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jan Bakuwel <jan.bakuwel@greenpeace.org>
To: pgsql-sql@postgresql.org
Subject: master/detail
Date: Mon, 21 May 2012 11:17:04 +1200
Message-ID: <4FB97B70.6080604@greenpeace.org> (raw)
In-Reply-To: <4FB8B489.3050701@gmx.net>
References: <4FB7EEC6.1030004@gmx.net>
	<jp9mvc$qmu$1@reversiblemaps.ath.cx>
	<4FB8B489.3050701@gmx.net>

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

Attachments:

  [application/pkcs7-signature] smime.p7s (3.6K, ../4FB97B70.6080604@greenpeace.org/2-smime.p7s)
  download

view thread (5+ messages)  latest in thread

Message-ID: <4FB97B70.6080604@greenpeace.org>
Permalink:  ../4FB97B70.6080604@greenpeace.org/
Also on:    postgresql.org/message-id/4FB97B70.6080604@greenpeace.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: jan.bakuwel@greenpeace.org
  Subject: Re: master/detail
  In-Reply-To: <4FB97B70.6080604@greenpeace.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox