AlexHeddell
MIS
I am trying to write a query that returns the customer who has bought the most of a product.
I have an Order table with CustomerID, ProductID and QtySold (amongst other things, obviously!!). If I do:
select CustomerID,ProductID,sum(QtySold) SumQtySold
into #Temp
from orders
group by CustomerID,ProductID
I can then find the max of the Product but I can't link it back to the customer
I'm sure I am missing something obvious here. Any help much appreciated
Alex
I have an Order table with CustomerID, ProductID and QtySold (amongst other things, obviously!!). If I do:
select CustomerID,ProductID,sum(QtySold) SumQtySold
into #Temp
from orders
group by CustomerID,ProductID
I can then find the max of the Product but I can't link it back to the customer
I'm sure I am missing something obvious here. Any help much appreciated
Alex