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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2007-01-24 : 08:22:07
|
| jumoke writes "HI Guys!pls i need ur help on how to find monthly average of values within a specific range of dates.e.g average of values between 2000-01-12 and 2000-01-12.i will like it to return 12 values, 1 for each month.thanks" |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-01-24 : 08:31:48
|
Can you post some sample data and the result that you want ? KH |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-24 : 09:34:52
|
| select dateadd(month, datediff(month, 0, {yourdatetimecolumnnamehere}), 0), avg({yourvaluecolumnnamehere})from {yourtablenamehere}where {yourdatetimecolumnnamehere} >= '20000101' and {yourdatetimecolumnnamehere} < '20070101'group by dateadd(month, datediff(month, 0, {yourdatetimecolumnnamehere}), 0)order by dateadd(month, datediff(month, 0, {yourdatetimecolumnnamehere}), 0)Peter LarssonHelsingborg, Sweden |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2007-01-24 : 10:39:08
|
| Darn, I thought this was going to be an interesting question when I saw the topic title. Average Date is one I never ran into before.CODO ERGO SUM |
 |
|
|
|
|
|
|
|