Daily maximum sold - daily

  • 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

  • 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

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • 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