I have a table called prices which stores prices for different contracts. Sample shown below.
id AsAt contract price
1 01/01/2012 1 6.5
2 02/01/2012 1 7
3 04/01/2012 1 5.2
4 04/01/2012 2 6
5 03/01/2012 2 9.1
6 01/02/2012 3 7
7 02/02/2012 3 6
8 03/02/2012 3 5.1
9 01/01/2012 4 6.5
I need to generate a resultset that shows the second to last date a price is quoted for. The final resultset would be:
contract penultimatepricedate
1 2/1/2012
2 3/1/2012
3 2/2/2012
4 1/1/2012
I can use the query
select contract,AsAt
from test.test_prices
where contract = 2
limit 1,1
To get the information for an individual contract but I can't seem to get the complete list (group by ???)
id AsAt contract price
1 01/01/2012 1 6.5
2 02/01/2012 1 7
3 04/01/2012 1 5.2
4 04/01/2012 2 6
5 03/01/2012 2 9.1
6 01/02/2012 3 7
7 02/02/2012 3 6
8 03/02/2012 3 5.1
9 01/01/2012 4 6.5
I need to generate a resultset that shows the second to last date a price is quoted for. The final resultset would be:
contract penultimatepricedate
1 2/1/2012
2 3/1/2012
3 2/2/2012
4 1/1/2012
I can use the query
select contract,AsAt
from test.test_prices
where contract = 2
limit 1,1
To get the information for an individual contract but I can't seem to get the complete list (group by ???)