The query I'm trying to develop return the following:
- The total amount of units sold of each product
- The name of the product
- The
CustomerIDthat has bought the max amount of each product
This is what I have so far:
SELECT DISTINCT
Products.ProductName,
SUM([Order Details].Quantity) as cant,
Orders.CustomerID
FROM
Products
INNER JOIN [Order Details]
ON Products.ProductID = [Order Details].ProductID
INNER JOIN Orders
ON [Order Details].OrderID = Orders.OrderID
WHERE
[Order Details].Quantity =
(
SELECT
MAX([Order Details].Quantity)
FROM
[Order Details]
WHERE
[Order Details].ProductID = Products.ProductID
)
GROUP BY
Products.ProductName, Orders.CustomerID
It's not giving me the results expected.
Any information related to the contents of the tables or anything else, just post it in a comment and I'll answer.
Thanks in advance for the help!