July 14, 2015 at 3:31 am
Hi
I have a code I wrote and I'm required to get Product Name and Quantity with the maximum quantity sold per day. My issue is with the "per day" part, if anyone can give me explanation as how how should I approve us problems, here's my code below.
SELECT
t.SalesOrder
,t.OrderQuantity
,t.OrderTotal
,t.OrderDate
,p.ProductName
FROM Transactions t
INNER JOIN SalesPerson sp
ON t.SalesPersonID = sp.SalesPersonID
INNER JOIN Product p
ON t.ProductID = p.ProductID
WHERE sp.SalesPersonName LIKE 'John%'
Now from this code I need to get only Product Name and Quantity with the maximum quantity sold per day, here's what I tried;
SELECT
SUM(t.OrderQuantity) AS Order_Quantity
,p.ProductName
FROM Transactions t
INNER JOIN Product p
ON t.ProductID = p.ProductID
WHERE sp.SalesPersonName LIKE 'John%'
GROUP BY p.ProductName, t.OrderQuantity
HAVING MAX(t.OrderQuantity)
Help please, daily max sold
July 14, 2015 at 3:33 am
Please don't post multiple threads for the same problem.
No replies to this thread please. Direct replies to http://www.sqlservercentral.com/Forums/Topic1702565-392-1.aspx
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
July 14, 2015 at 3:38 am
I posted on SQL Server 2008, Now I'm moving it to SQL Server 2012.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply