I'm trying to Display for each year, the customer who purchased the highest amount in Northwind database using SQL.
SELECT
YEAR(o.OrderDate) AS OrderYear,
MAX(od.Quantity) AS MaxQuantity
FROM
Customers c
JOIN Orders o ON c.CustomerID = o.CustomerID
JOIN [Order Details] od ON o.OrderID = od.OrderID
GROUP BY
YEAR(o.OrderDate)
That's what I managed to do. I just need some help with displaying the customer id for each one of the years.
I think it would make more sense to get the SUM rather than MAX per person for each year. Here we can use the row_number() function to rank people.
If you really want MAX, then replace SUM with MAX in both occurrences.