Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Group by month and then average

Status
Not open for further replies.
Dec 11, 2000
46
US
I would like to build a query that would group all records by year/month and then average each month.
For example the output of each row might look like this: "Jan 02, 55" then each row would show subsequent months.

 
select format(somedate, "mmm")
, format(somedate, "yy")
, avg(somevalue)
from yourtable
group
by format(somedate, "mmm")
, format(somedate, "yy")
order
by 2,1

note that splitting the format into month name and year pieces is necessary to provide a meaningful sort (otherwise, you'd get Apr, Aug, Dec, etc.)

rudy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top