Query Help :)

  • Hi,Guys i have a task for daily report in SQL 2012 r2  so i have to take all customer ID from table Orders, which have Purchase order so i write something but its not enough i need to separete for each months i have one column OrderDate but need to count them  like
    ALFKI           3                Jan 2000
    ALFKI           2                 December 2000
    THEBI           4                Feb 2001

    etc.
    Chek my query for now i count all names and countPurchase

    SELECT Orders.CustomerID, COUNT(Orders.OrderID) as CountPurchase
     FROM Orders
       GROUP BY Orders.CustomerID

    Thank you 🙂

  • ndoee - Tuesday, September 26, 2017 5:13 AM

    Hi,Guys i have a task for daily report in SQL 2012 r2  so i have to take all customer ID from table Orders, which have Purchase order so i write something but its not enough i need to separete for each months i have one column OrderDate but need to count them  like
    ALFKI           3                Jan 2000
    ALFKI           2                 December 2000
    THEBI           4                Feb 2001

    etc.
    Chek my query for now i count all names and countPurchase

    SELECT Orders.CustomerID, COUNT(Orders.OrderID) as CountPurchase
     FROM Orders
       GROUP BY Orders.CustomerID

    Thank you 🙂

    So why not add another column containing 'month year' to the SELECT and to the GROUP BY?

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply