Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Group and Average Query?

Author  Topic 

Shanew
Starting Member

20 Posts

Posted - 2009-10-02 : 12:42:07
Hello,

Not sure how to do this query…

I have a table with 2 fields:
- Date
- Size (vales range between 1 and 100)

Is it possible in a query to group the values by month and then have the query average the size for each month?

Thanks for any help!
Shane

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-10-02 : 12:50:22
yup. its possible

SELECT DATEADD(mm,DATEDIFF(mm,0,Date),0),
AVG(Size*1.0)
FROM Table
GROUP BY DATEADD(mm,DATEDIFF(mm,0,Date),0)
Go to Top of Page
   

- Advertisement -