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.
| Author |
Topic |
|
Jumoke
Starting Member
2 Posts |
Posted - 2007-01-22 : 05:40:16
|
| hi guys, i got range of values in a daily date format and the are of datatype smalldatetime but, the values are daily and i want to find average of those values based on month.NOTE: the value may not necessary be up to 30 or 31 dayse.g average of values from january 1, 2000 to december 29, 2006 based on month i.e one value for each distinct month |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-22 : 05:44:09
|
| select dateadd(month, datediff(month, 0, yourdatetimecolumn), 0), avg(anothercolumnnamehere)from yourtablenameherewhere yourdatetimecolumn >= '20000101' and yourdatetimecolumn < '20070101'group by dateadd(month, datediff(month, 0, yourdatetimecolumn), 0)Peter LarssonHelsingborg, Sweden |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-22 : 06:00:41
|
| select dateadd(month, datediff(month, 0, yourdatetimecolumn), 0), avg(anothercolumnnamehere),min(anothercolumnnamehere),max(anothercolumnnamehere),count(anothercolumnnamehere),sum(anothercolumnnamehere)from yourtablenameherewhere yourdatetimecolumn >= '20000101' and yourdatetimecolumn < '20070101'group by dateadd(month, datediff(month, 0, yourdatetimecolumn), 0)Peter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|
|
|