G
Guest
Dear All (again)!
I have the follwoing table, Sheet 1:
ID PartNo Qty InvDate Price
1 LH01040038 4 01/01/2001 459.92
2 LH01040038 4 01/01/2002 454.02
3 LH01040038 4 01/01/2003 430.02
4 LH12345678 3 01/01/2004 50.99
I require output of ONLY the PartNo and the most recent price ever paid (ie
Price at MAX InvDate). Expected Output would thus be:
LH01040038 430.02
LH12345678 50.99
I am using the following code:
SELECT Q.partno, Q.Price
FROM Sheet1 AS Q
WHERE Q.invdate = (SELECT Max(T.invdate) FROM Sheet1 AS T Where T.invdate =
Q.invdate);
But the output is not as I would expect:
partno Price
LH01040038 459.92
LH01040038 454.02
LH01040038 454.02
This is actually just a small sample of the data I'm using to test the
coding of the queries, the final query is to be run on thousands of lines of
data so I need to be sure that each part number only appears once with its
latest price.
Where am I going wrong?
I have the follwoing table, Sheet 1:
ID PartNo Qty InvDate Price
1 LH01040038 4 01/01/2001 459.92
2 LH01040038 4 01/01/2002 454.02
3 LH01040038 4 01/01/2003 430.02
4 LH12345678 3 01/01/2004 50.99
I require output of ONLY the PartNo and the most recent price ever paid (ie
Price at MAX InvDate). Expected Output would thus be:
LH01040038 430.02
LH12345678 50.99
I am using the following code:
SELECT Q.partno, Q.Price
FROM Sheet1 AS Q
WHERE Q.invdate = (SELECT Max(T.invdate) FROM Sheet1 AS T Where T.invdate =
Q.invdate);
But the output is not as I would expect:
partno Price
LH01040038 459.92
LH01040038 454.02
LH01040038 454.02
This is actually just a small sample of the data I'm using to test the
coding of the queries, the final query is to be run on thousands of lines of
data so I need to be sure that each part number only appears once with its
latest price.
Where am I going wrong?