I have a table that holds a Bill of Material structure for an application. Fields are Parent, Component, EffectiveDate, Qty. The table of data looks like this:
Car - STDWheel - 1/1/2000 - 4
Car - STDWheel - 6/6/2005 - 0
Car - MAGWheel - 6/6/2005 - 4
Car - GoodTire - 1/1/2000 - 4
Car - GoodTire - 6/6/2005 - 0
Car - GreatTire - 6/6/2005 - 4
The way the application uses its data in this example shows that on 1/1/2000 the Car was made of 4 STDWheels and 4 GoodTires. On 6/6/2005 the StdWheels and GoodTires were replaced with MAGWheels and GreatTires. The reason the STDWheels and GoodTires have the 0 qty record is to show that these items are to start showing on the materials list on 1/1/2000 and stop showing on 6/6/2006.
In MS Access or MS SQL if i wanted to get the latest version of the parts list I would do the following:
Select Last(Parent),
Last(Component),
Last(EffectiveDate),
Last(QTY)
From ProductStructure
Where Parent = 'MyPart'
Order by Component, EffectiveDate
Which would return
Car - STDWheel - 6/6/2005 - 0
Car - MAGWheel - 6/6/2005 - 4
Car - GoodTire - 6/6/2005 - 0
Car - GreatTire - 6/6/2005 - 4
(Note: the 0's are OK because they are eliminated in another step)
My problem is that it looks like PSQL 2000i does not have a LAST option or I am just not getting the syntax correct.
Car - STDWheel - 1/1/2000 - 4
Car - STDWheel - 6/6/2005 - 0
Car - MAGWheel - 6/6/2005 - 4
Car - GoodTire - 1/1/2000 - 4
Car - GoodTire - 6/6/2005 - 0
Car - GreatTire - 6/6/2005 - 4
The way the application uses its data in this example shows that on 1/1/2000 the Car was made of 4 STDWheels and 4 GoodTires. On 6/6/2005 the StdWheels and GoodTires were replaced with MAGWheels and GreatTires. The reason the STDWheels and GoodTires have the 0 qty record is to show that these items are to start showing on the materials list on 1/1/2000 and stop showing on 6/6/2006.
In MS Access or MS SQL if i wanted to get the latest version of the parts list I would do the following:
Select Last(Parent),
Last(Component),
Last(EffectiveDate),
Last(QTY)
From ProductStructure
Where Parent = 'MyPart'
Order by Component, EffectiveDate
Which would return
Car - STDWheel - 6/6/2005 - 0
Car - MAGWheel - 6/6/2005 - 4
Car - GoodTire - 6/6/2005 - 0
Car - GreatTire - 6/6/2005 - 4
(Note: the 0's are OK because they are eliminated in another step)
My problem is that it looks like PSQL 2000i does not have a LAST option or I am just not getting the syntax correct.