Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2010

    Unanswered: Quick query help

    I have the below Straight forward query to count the number of Sales for an agent for a week and it returns the below result;

    Firstname Surname Sales for the week
    Aaron Thorne 12
    Adam Cameron 3
    Adrian Betambeau 6

    My question is how do I modify the query to extract an average for the week; for example I want the extract to provide a result that looks like the below

    Firstname Surname Sales for the week Average sale per week
    Aaron Thorne 12 2.4
    Adam Cameron 3 0.6
    Adrian Betambeau 6 1.2

    SELECT Users.FirstName ,
    Users.Surname ,
    FROM Users
    JOIN [3directorder]
    ON [3directorder].AgentID = Users.UserID
    where [3directorder].StartDate between '2010-10-18 00:00:00.000' and '2010-10-22 23:00:00.000'
    and [3directorder].OrderStatusID in ('Pass','Confirmed By Three')
    group by Users.FirstName, Users.Surname
    order by Users.FirstName, Users.Surname

    Any help would be appreciated.


  2. #2
    Join Date
    Apr 2002
    Toronto, Canada
    Quote Originally Posted by DanBay View Post
    Any help would be appreciated.
    i'll give you a hint, the answer will involve an aggregate function known as AVG()

    you've already used one aggregate function, COUNT() | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts