Monday, March 12, 2012

MS SQL date range and average

Hi

I am very new to SQL so please excuse this if it is a very simple question - I have 5 colunms of data and one of them is a "date" - what would the SQL query be to sort the data into days with the average of the other fields. ie I have per "5 minute" logging going into the data base for fields 1,2,3,4 and field 0 is the date - I am trying to get the averages of fields 1,2,3,4 for the day.

Any help will be greatly appreciated.Something like

SELECT DATE_FORMAT(date, ""%Y/%m/%d") AS Day, AVG(Field1), AVG(Field2), AVG(Field3), AVG(Field4) FROM Table GROUP By Day;

I believe.

No comments:

Post a Comment