Average Sold Per Month Query

  • Hi all,

    I have a standard orderdetail table which contains the fields:

    customer,product,dated,qty

    and would like to be able to return the:

    AVERAGE QTY SOLD MONTHLY per PRODUCT as a single figure

    ie - i don't want avg in Jan,Feb,Mar,Apr... etc

    but the OVERALL average across all years and months by product

    Hope i've explained this ok

    Thanks in advance,

    Mark

  • SELECT DATEPART(YEAR, SaleDate) SaleYear, Product, AVG(SaleQty)/12 AvgSalesPerMonth

    FROM

     orderdetail

    GROUP BY DATEPART(YEAR, SaleDate), Product

    Regards,
    gova

  • Not sure but shouldn't it be :

    SELECT DATEPART(YEAR, SaleDate) SaleYear, Product, SUM(SaleQty)/12[.0] AvgSalesPerMonth

    FROM

    orderdetail

    GROUP BY DATEPART(YEAR, SaleDate), Product

    as the /12 actually takes care of the average .

  • I was in a hurry to beat you and lost again.

    Regards,
    gova

  • Don't worry about it... it's gonna happen again .

    It's not like I'm trying to type slower with each passing day or anything .

  • Not sure but shouldn't it be :

    SELECT DATEPART(YEAR, SaleDate) SaleYear, Product, AVG(SaleQty)AvgSales

    FROM

    orderdetail

    GROUP BY DATEPART(YEAR, SaleDate), Product

    At least that's what I interpret by accross all years and months

     


    * Noel

  • Ya wasn't too sure about that myself... but I'm wondering why someone would need that info... I guess we'll know later on.

  • Guessing is a good part of this kind of questions .... I'd guess 


    * Noel

  • I must be getting old - I didn't even think about the standard maths '/12' solution to this problem -

    Thanks guys for reminding me just how stupid i really am !!!

     

  • Don't put it like that, and you're welcomed .

  • Ya, those questions are simple enough where you don't really lose time if you're wrong... and you can't be all that wrong anyways .

  • Is you'r welcomed forum standard now!!!! Thanks to noel.

     

    Regards,
    gova

  • What do you mean?

  • If you looked at the poster you guessed it right!


    * Noel

  • You don't remember Remi. Check this.

    http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=8&messageid=207434#bm207636

    Regards,
    gova

Viewing 15 posts - 1 through 15 (of 29 total)

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