robertsfd
Technical User
- Apr 18, 2003
- 40
I have a table with the following structure:
Sales(CustomerID, Name, Date, InventoryName, Amount, CheckNumber)
This is a table with every sale for a number of years, containing a customer's ID, their name, the date of the sale, what they bought, the amount they paid, and their check number.
I want to find the largest and second largest amount for each customer.
To find the largest amount for each, I do the following:
SELECT CustomerID, Max(Amount) AS MaxAmount
FROM Sales
GROUP BY CustomerID;
But I cannot figure out how to find the second largest amount. Anyone know how to do this? Thanks!
Sales(CustomerID, Name, Date, InventoryName, Amount, CheckNumber)
This is a table with every sale for a number of years, containing a customer's ID, their name, the date of the sale, what they bought, the amount they paid, and their check number.
I want to find the largest and second largest amount for each customer.
To find the largest amount for each, I do the following:
SELECT CustomerID, Max(Amount) AS MaxAmount
FROM Sales
GROUP BY CustomerID;
But I cannot figure out how to find the second largest amount. Anyone know how to do this? Thanks!