Hi,
I currently have the following data:
Category Amount EffectiveDate
Apple 10 10/06/2011
Apple 4 06/06/2011
Apple 13 01/06/2011
Banana 8 10/06/2011
Banana 6 06/06/2011
Banana 9 01/06/2011
Orange 14 10/06/2011
Orange 2 06/06/2011
Orange 8 01/06/2011
I need to get the most recent amount for each category, but I don't want the EffectiveDate column to be SELECTed.
So I couldn't have:
I need the output to be:
Category Amount
Apple 10
Banana 8
Orange 14
How would I do this?
Edit: Forgot to say, as always, this is SQL Server 2005
I currently have the following data:
Category Amount EffectiveDate
Apple 10 10/06/2011
Apple 4 06/06/2011
Apple 13 01/06/2011
Banana 8 10/06/2011
Banana 6 06/06/2011
Banana 9 01/06/2011
Orange 14 10/06/2011
Orange 2 06/06/2011
Orange 8 01/06/2011
I need to get the most recent amount for each category, but I don't want the EffectiveDate column to be SELECTed.
So I couldn't have:
Code:
SELECT Category, Amount, MAX(EffectiveDate)
FROM Fruits
GROUP BY Category, Amount
I need the output to be:
Category Amount
Apple 10
Banana 8
Orange 14
How would I do this?
Edit: Forgot to say, as always, this is SQL Server 2005