August 18, 2005 at 8:05 am
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
August 18, 2005 at 8:08 am
SELECT DATEPART(YEAR, SaleDate) SaleYear, Product, AVG(SaleQty)/12 AvgSalesPerMonth
FROM
orderdetail
GROUP BY DATEPART(YEAR, SaleDate), Product
Regards,
gova
August 18, 2005 at 8:13 am
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 .
August 18, 2005 at 8:17 am
I was in a hurry to beat you and lost again.
Regards,
gova
August 18, 2005 at 8:20 am
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 .
August 18, 2005 at 8:32 am
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
August 18, 2005 at 8:34 am
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.
August 18, 2005 at 8:40 am
Guessing is a good part of this kind of questions .... I'd guess
* Noel
August 18, 2005 at 8:40 am
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 !!!
August 18, 2005 at 8:41 am
Don't put it like that, and you're welcomed .
August 18, 2005 at 8:42 am
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 .
August 18, 2005 at 8:43 am
Is you'r welcomed forum standard now!!!! Thanks to noel.
Regards,
gova
August 18, 2005 at 8:44 am
What do you mean?
August 18, 2005 at 8:45 am
If you looked at the poster you guessed it right!
* Noel
August 18, 2005 at 8:50 am
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