Home > Archive > MS SQL Server > October 2006 > Query.....help









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Query.....help
amatuer

2006-10-24, 6:37 pm

Cloumn Name, Data type, length, allow nulls:

ID int 4 0
NAAM nvarchar 254 1
DATUM smalldatetime 4 1
Dag int 4 1
Maand int 4 1
Jaar int 4 1
Reenval_Silo float 8 1


Using this table i need to get the average of "Reenval_Silo" per month
for "NAAM " for the years 2006, 2005 & 2004

Any help will be highly appreciated...thnx in advance

Uri Dimant

2006-10-24, 6:37 pm

Hi
Since you have not posted DDL+ sample data + an expected result , I'll give
an idea about how you van do that

--Average of quantity per year group by stor_id

SELECT
stor_id,
AVG(CASE YEAR(ord_date)
WHEN 2004 THEN qty
ELSE 0
END) AS c2004 ,
AVG(CASE YEAR(ord_date)
WHEN 2005 THEN qty
ELSE 0
END) AS c2005 ,
AVG(CASE YEAR(ord_date)
WHEN 2006 THEN qty
ELSE 0
END) AS c2006
FROM Sales
GROUP BY stor_id
ORDER BY stor_id




"amatuer" <njoosub@gmail.com> wrote in message
news:1160723854.407946.4020@k70g2000cwa.googlegroups.com...
> Cloumn Name, Data type, length, allow nulls:
>
> ID int 4 0
> NAAM nvarchar 254 1
> DATUM smalldatetime 4 1
> Dag int 4 1
> Maand int 4 1
> Jaar int 4 1
> Reenval_Silo float 8 1
>
>
> Using this table i need to get the average of "Reenval_Silo" per month
> for "NAAM " for the years 2006, 2005 & 2004
>
> Any help will be highly appreciated...thnx in advance
>



Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2009 droptable.com